Created
February 27, 2014 13:43
-
-
Save ear1grey/9250224 to your computer and use it in GitHub Desktop.
An example javascript closure, with public / private vars and a shortcut function.
This file contains hidden or 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 example = (function() { | |
var | |
fn1 = function() {return fn2();}, | |
fn2 = function() {return "b";}; | |
return { | |
"pubfn1": fn1 | |
}; | |
})(); | |
console.log(example.fn1); | |
console.log(example.fn2); | |
console.log(example.pubfn1); | |
console.log(example.pubfn1()); | |
var shortcut = example.pubfn1; | |
console.log(shortcut()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment