Skip to content

Instantly share code, notes, and snippets.

@edwardsharp
Created May 7, 2013 04:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edwardsharp/5530228 to your computer and use it in GitHub Desktop.
Save edwardsharp/5530228 to your computer and use it in GitHub Desktop.
mmm, scope...
var module = {
getUser: function() {
return this.user;
},
user: "jim user"
};
> undefined
module.getUser();
> "jim user"
//this could be another annon function!
> undefined
var user = "jane user";
> undefined
//call getUser function on the global this scope
> undefined
var getUser = module.getUser;
> undefined
module.getUser();
> "jim user"
getUser();
> "jane user"
//cool! okay, we can also bind thingz...
> undefined
var boundGetUser = getUser.bind( module );
> undefined
boundGetUser();
> "jim user"
//...remember?
> undefined
getUser();
> "jane user"
//thx for not reassigning the module object!
> undefined
module.getUser();
> "jim user"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment