Как в этом случае сохранить контекст и избежать ошибок при первом и повторном вызове window.requestAnimationFrame ?
'use strict';
class Game{
constructor(context){
this.context = context;
this.gameUpdate;
this.updatePerSecond = 10;
}
initiate(){
this.gameUpdate = setInterval(this.update, 1000 / this.updatePerSecond);
window.requestAnimationFrame(this.draw);
}
update(){
}
draw(){
window.requestAnimationFrame(this.draw);
}
}
var game = new Game('123');
game.initiate();
window.requestAnimationFrame(this.draw.bind(this));– Jan 19 '18 at 16:00