Created
June 28, 2017 11:53
-
-
Save X-Raym/279ef95148977b9bdaed6af735fc0f43 to your computer and use it in GitHub Desktop.
Access JavaScript Object Property from a Method
This file contains hidden or 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
| var obj = function() { | |
| var self = this; // This is the trick | |
| this.data = "4"; | |
| this.do = function() { | |
| return self.data; // This is how to use it | |
| } | |
| } | |
| var test = new obj; | |
| console.log( test.do() ); | |
| // display 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment