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
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
JavaScript Module Pattern
(function(){
// a module
}());
= Immediately-Invoked Function Expressions
Ben Almanhttp://benalman.com/news/2010/11/immediately-invoked-function-expression/
(function(){
// private scope var id = "abc123";
function logout(){ location = "/logout?"+id; }
}());
/*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));
github.com/eric-brechemier/scopeornot
scope(function(){
// a module
});
scope(function(context){
// private scope var id = "abc123";
function logout(){ location = "/logout?"+id; }
});
/*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");
2011-12-21 11 /
THANK YOU!
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