Skip to content

Instantly share code, notes, and snippets.

@cld-santos
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cld-santos/11005743 to your computer and use it in GitHub Desktop.
Save cld-santos/11005743 to your computer and use it in GitHub Desktop.
How closure works guided by code.
console.clear();
console.log('init Test');
var globalVar = "global";
function myObject(value){
var test="private"+value;
this.testLog = function(){
console.log(test + ":" + globalVar);
};
return this;
}
//When I use the new keyword, I made a new scope,
var testObject = new myObject("initialized");
console.log('start Test');
testObject.testLog();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment