Skip to content

Instantly share code, notes, and snippets.

@ear1grey
Created February 27, 2014 13:43
Show Gist options
  • Save ear1grey/9250224 to your computer and use it in GitHub Desktop.
Save ear1grey/9250224 to your computer and use it in GitHub Desktop.
An example javascript closure, with public / private vars and a shortcut function.
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