Skip to content

Instantly share code, notes, and snippets.

@Lewuathe
Created November 12, 2012 00:49
Show Gist options
  • Save Lewuathe/4056955 to your computer and use it in GitHub Desktop.
Save Lewuathe/4056955 to your computer and use it in GitHub Desktop.
Pattern of the reference to this object in instance method.
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