我試圖以面向對象的方式組織我的代碼(如MDN中所述)。然而在我的情況下,這個指的是窗口對象。因爲我得到的錯誤JavaScript範圍問題(this)
Uncaught TypeError: Cannot read property 'render' of undefined
在
this.renderer.render(this.stage);
爲什麼這是指當它不會對MDN窗口對象?
var GAME = GAME || {};
GAME.Application = function() {
this.renderer = PIXI.autoDetectRenderer(800, 600,{backgroundColor : 0x1099bb});
document.getElementById("game").appendChild(this.renderer.view);
this.stage = new PIXI.Container();
requestAnimationFrame(this.render);
}
GAME.Application.prototype.render = function() {
this.renderer.render(this.stage);
}
var app = new GAME.Application();