Skip to content

Instantly share code, notes, and snippets.

@raytiley
Created April 22, 2012 23:57
Show Gist options
  • Save raytiley/2467619 to your computer and use it in GitHub Desktop.
Save raytiley/2467619 to your computer and use it in GitHub Desktop.
Design Phase 4 - Closure Example
var module = function(){
var privateVar = “I’m out of scope since function executes and returns”;
//getPrivateVar is a property of the returned function.
this.getPrivateVar = function() {
return privateVar;
}
}(); // () causes anonymous function to automatically execute
module.getPrivateVar === “I’m out of scope since function executes and returns”; //true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment