Created
November 30, 2012 16:56
-
-
Save zhannes/4176977 to your computer and use it in GitHub Desktop.
javascript scoping - 3
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
/* ######################### | |
3 - SCOPE - Define a function in a closure, return an object that has access to that function. | |
*/ | |
(function(){ | |
// accessible via the object we return | |
var o = (function(){ | |
// local | |
function _f(){ _log( 'danneh' ); } | |
// public exports | |
return { | |
foo: _f | |
}; | |
})(); | |
o.foo(); // works, and no-one can modify _foo | |
_log( this._f ); // undefined | |
})(); | |
_log( window._f ); // undefined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment