我正在使用,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)