对象变量返回undefined

时间:2016-07-15 11:59:54

标签: javascript

当我运行下面的代码时出现错误 - “无法读取未定义的属性'drawGame'”。为什么呢?

function Game() {
    this.renderer = new Renderer(this.player);
    this.startGame();
}

Game.prototype.startGame = function() {
    this.renderer.drawGame(); //here error occurs
    setTimeout(this.startGame, 20);
};

function Renderer(){
}

Renderer.prototype.drawGame = function() {
    //function content
};

0 个答案:

没有答案