Your SlideShare is downloading. ×
0
scope or not?
scope or not?
scope or not?
scope or not?
scope or not?
scope or not?
scope or not?
scope or not?
scope or not?
scope or not?
scope or not?
scope or not?
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

scope or not?

1,008

Published on

CC-BY-SA Eric Bréchemier …

CC-BY-SA Eric Bréchemier
https://github.com/eric-brechemier/scopeornot-presentation

Presentation of the scopeornot library at ParisJS on December 21st, 2011.

Quoting the README of the scopeornot library:

"This project defines a single function scope() with multiple implementations. The goal is to make definition of modules and private scopes slightly simpler than using JavaScript Module pattern, and flexible enough to switch from static to dynamic module loading. You can choose one of the provided scope() implementations, replace it with another, tweak it to your needs, or create your own."

scopeornot on GitHub:
https://github.com/eric-brechemier/scopeornot

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,008
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
2
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. scope or not? ParisJS, December 21 st 2011
  • 2. JavaScript Module Pattern
  • 3. ( function(){ // a module } () ) ;
  • 4. = Immediately-Invoked Function Expressions <ul>Ben Alman http://benalman.com/news/2010/11 /immediately-invoked-function-expression/ </ul>
  • 5. ( function(){ // private scope var id = &amp;quot;abc123&amp;quot;; function logout (){ location = &amp;quot;/logout?&amp;quot;+id; } } () ) ;
  • 6. /*global APP:true, window */ var APP = APP || {}; APP.session = APP.session || ( function(window,user){ // Public API return { logout: function(){ window.location = &amp;quot;/logout?&amp;quot;+user.id(); } }; } (window,APP.user) ) ;
  • 7. github.com/eric-brechemier / scopeornot
  • 8. scope ( function(){ // a module } ) ;
  • 9. scope ( function( context ){ // private scope var id = &amp;quot;abc123&amp;quot;; function logout (){ location = &amp;quot;/logout?&amp;quot;+id; } } ) ;
  • 10. /*global scope */ scope( function(context){ // Declare aliases var window = context. window , user = context[&amp;quot; APP.user &amp;quot;]; // Public API return { logout: function(){ window.location = &amp;quot;/logout?&amp;quot;+user.id(); } }; }, [&amp;quot; window &amp;quot;,&amp;quot; APP.user &amp;quot;], &amp;quot; APP.session &amp;quot; ) ;
  • 11. THANK YOU!
  • 12. Credits &amp; Further Reading <ul><li>Slide Template </li><ul><li>Adapted from &amp;quot;tokyo-midtown-1.otp&amp;quot; CC-BY-SA Chih-Hao Tsai </li></ul><li>JavaScript Module Pattern: In-Depth
  • 13. JavaScript Scoping and Hoisting </li><ul><li>by Ben Cheery </li></ul><li>Unnecessarily comprehensive look into a rather insignificant issue of global objects creation </li><ul><li>by kangax </li></ul></ul>https://github.com/eric-brechemier/scopeornot-presentation

×