scope or not?
DESCRIPTION
CC-BY-SA Eric Bréchemierhttps://github.com/eric-brechemier/scopeornot-presentationPresentation 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/scopeornotTRANSCRIPT
![Page 1: scope or not?](https://reader038.vdocuments.us/reader038/viewer/2022100604/5597348d1a28ab7a338b4638/html5/thumbnails/1.jpg)
Eric BréchemierEric Bréchemier
@eric_brechemier@eric_brechemier
github.com/eric-brechemiergithub.com/eric-brechemier
scope or not?
ParisJS, December 21ParisJS, December 21stst 2011 2011
![Page 2: scope or not?](https://reader038.vdocuments.us/reader038/viewer/2022100604/5597348d1a28ab7a338b4638/html5/thumbnails/2.jpg)
JavaScript Module Pattern
![Page 3: scope or not?](https://reader038.vdocuments.us/reader038/viewer/2022100604/5597348d1a28ab7a338b4638/html5/thumbnails/3.jpg)
(function(){
// a module
}());
![Page 4: scope or not?](https://reader038.vdocuments.us/reader038/viewer/2022100604/5597348d1a28ab7a338b4638/html5/thumbnails/4.jpg)
= Immediately-Invoked Function Expressions
Ben Almanhttp://benalman.com/news/2010/11/immediately-invoked-function-expression/
![Page 5: scope or not?](https://reader038.vdocuments.us/reader038/viewer/2022100604/5597348d1a28ab7a338b4638/html5/thumbnails/5.jpg)
(function(){
// private scope var id = "abc123";
function logout(){ location = "/logout?"+id; }
}());
![Page 6: scope or not?](https://reader038.vdocuments.us/reader038/viewer/2022100604/5597348d1a28ab7a338b4638/html5/thumbnails/6.jpg)
/*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));
![Page 7: scope or not?](https://reader038.vdocuments.us/reader038/viewer/2022100604/5597348d1a28ab7a338b4638/html5/thumbnails/7.jpg)
github.com/eric-brechemier/scopeornot
![Page 8: scope or not?](https://reader038.vdocuments.us/reader038/viewer/2022100604/5597348d1a28ab7a338b4638/html5/thumbnails/8.jpg)
scope(function(){
// a module
});
![Page 9: scope or not?](https://reader038.vdocuments.us/reader038/viewer/2022100604/5597348d1a28ab7a338b4638/html5/thumbnails/9.jpg)
scope(function(context){
// private scope var id = "abc123";
function logout(){ location = "/logout?"+id; }
});
![Page 10: scope or not?](https://reader038.vdocuments.us/reader038/viewer/2022100604/5597348d1a28ab7a338b4638/html5/thumbnails/10.jpg)
/*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");
![Page 11: scope or not?](https://reader038.vdocuments.us/reader038/viewer/2022100604/5597348d1a28ab7a338b4638/html5/thumbnails/11.jpg)
2011-12-21 11 /
THANK YOU!
![Page 12: scope or not?](https://reader038.vdocuments.us/reader038/viewer/2022100604/5597348d1a28ab7a338b4638/html5/thumbnails/12.jpg)
2011-12-21 12 /
Credits & Further Reading
Slide TemplateAdapted from "tokyo-midtown-1.otp"
CC-BY-SA Chih-Hao Tsai
JavaScript Module Pattern: In-DepthJavaScript Scoping and Hoisting
by Ben CheeryUnnecessarily comprehensive look into a rather
insignificant issue of global objects creation by kangax
https://github.com/eric-brechemier/scopeornot-presentation