Skip to content

Instantly share code, notes, and snippets.

@escusado
Created June 5, 2014 19:36
Show Gist options
  • Save escusado/5c68d228f4a82fc03e78 to your computer and use it in GitHub Desktop.
Save escusado/5c68d228f4a82fc03e78 to your computer and use it in GitHub Desktop.
Class('MyClass')({
prototype : {
init : function (options){
this.myProperty = 'value';
this.myMethod();
},
myMethod : function(){
var myArbitraryNamedClosue = this;
console.log('This is my: ', this.myProperty); // this is my: value
['a', 'b', 'c'].forEach(function(){
//without a closure
console.log('This is my: ', this.myProperty); // this is my: undefined
//with closue
console.log('This is my: ', myArbitraryNamedClosue.myProperty); // this is my: velue
});
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment