scope or not?

1,312 views

Published on

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,312
On SlideShare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
4
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

scope or not?

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

×