相关疑难解决方法(0)

requestAnimationFrame与此关键字

我正在使用,webkitRequestAnimationFrame但我在一个对象内部使用它时遇到了麻烦.如果我传递this它将使用的关键字window,我找不到使用指定对象的方法.

例:

Display.prototype.draw = function(){
  this.cxt.clearRect(0, 0, this.canvas.width, this.canvas.height);
  //Animation stuff here.

  window.webkitRequestAnimationFrame(this.draw);
};
Run Code Online (Sandbox Code Playgroud)

我也试过这个,但无济于事:

Display.prototype.draw = function(){
  this.cxt.clearRect(0, 0, this.canvas.width, this.canvas.height);
  //Animation stuff here.

  var draw = this.draw;
  window.webkitRequestAnimationFrame(draw);
};
Run Code Online (Sandbox Code Playgroud)

javascript animation object this

44
推荐指数
3
解决办法
2万
查看次数

标签 统计

animation ×1

javascript ×1

object ×1

this ×1