!CLOSED!
嘿,我一直在乱用JavaScript中的对象,我遇到了一个问题:
function Game(name, canvas, width, height, fps)
{
this.name = name;
this.canvas = document.getElementById(canvas);
this.ctx = this.canvas.getContext('2d');
this.width = width;
this.height = height;
this.fps = fps;
}
Game.prototype.gameloop = function()
{
//Clear Screen
this.canvas.width = this.canvas.width;
//Update
//Update();
//Draw
Draw(this.ctx);//this is now pointing at 'Game'
};
Game.prototype.start = function() {
this.interval = setInterval(this.gameloop.bind(this),this.fps);
};
我无法弄清楚为什么在这种情况下'this'关键字不指向'Game'
有什么建议吗?