0

!关闭!

嘿,我一直在搞乱 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”

有什么建议么?

4

0 回答 0