Skip to content

Instantly share code, notes, and snippets.

@X-Raym
Created June 28, 2017 11:53
Show Gist options
  • Select an option

  • Save X-Raym/279ef95148977b9bdaed6af735fc0f43 to your computer and use it in GitHub Desktop.

Select an option

Save X-Raym/279ef95148977b9bdaed6af735fc0f43 to your computer and use it in GitHub Desktop.
Access JavaScript Object Property from a Method
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