Created
June 5, 2014 19:36
-
-
Save escusado/5c68d228f4a82fc03e78 to your computer and use it in GitHub Desktop.
This file contains 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
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