Created
May 7, 2013 04:18
-
-
Save edwardsharp/5530228 to your computer and use it in GitHub Desktop.
mmm, scope...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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