Javascript setInterval() in OOP Style Not Working -


im creating program move object repeatedly using javascript. functions work when separated when try use oop pattern gives strange error repeatedly saying

uncaught typeerror: this.move not function 

here code

function bot(){      this.xpos =0;      this.ypos=0;      this.asyncmove=setinterval(function(){           this.xpos+=10;          this.ypos+=10;          this.move();      },100); }  bot.prototype = {      constructor:bot,      move:function(){          console.log(this.xpos+" ,"+this.ypos);      }  }; 

you should bind current instance anonymous function this

this.asyncmove=setinterval(function(){      this.xpos+=10;     this.ypos+=10;     this.move(); }.bind(this),100); 

Comments