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

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -