Created
November 12, 2012 00:49
-
-
Save Lewuathe/4056955 to your computer and use it in GitHub Desktop.
Pattern of the reference to this object in instance method.
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
function Obj(){ | |
this.prop = 'PROP'; | |
} | |
Obj.prototype.refToProp = function(){ | |
// Only self can refer to the Obj instance object. | |
// So if you want to refer in other function, self variable is need to be defined. | |
var self = this; | |
setTimeout(function(){ | |
console.log(self.prop); | |
},1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment