javascript - how to make setTimeout refer to context of object? -
var myobj = { name:"mike", go:function(){ console.log(this.name); } } myobj.go() //logs out mike settimeout(this.myobj.go,200) //logs out (emptystring)
define variable reffering object before:
var _this = this; settimeout(function() {_this.myobj.go();}, 200);
Comments
Post a Comment