scope or not?
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

scope or not?

on

  • 1,164 views

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

Statistics

Views

Total Views
1,164
Views on SlideShare
1,158
Embed Views
6

Actions

Likes
2
Downloads
2
Comments
0

3 Embeds 6

http://www.thelibrarynews.com 4
http://www.linkedin.com 1
https://www.linkedin.com 1

Accessibility

Categories

Upload Details

Uploaded via as OpenOffice

Usage Rights

CC Attribution-ShareAlike LicenseCC Attribution-ShareAlike License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

scope or not? Presentation Transcript

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