我正在重複使用舊的應用程序(遊戲),因此可以運行幾個遊戲。 由於這個原因,我已經將屬性更改爲「this.propery」,這在我的應用程序中隨處可見。 但是,唯一可以訪問屬性的原型函數是「startGame」。 我已經嘗試了「this.bricks」和「Game.bricks」,但是在嘗試在任何其他「startGame」函數中嘗試觸及它們時都未定義。從原型函數訪問屬性
我的任何提示?
var game = new Game();
game.startGame();
Game = function(){
this.bricks = 2;
this.checkOddEven = 0;
...
}
Game.prototype.startGame = function() {
console.log(this.bricks) <- 2
console.log(Game.bricks) <- 2
// Code goes here...
Game.prototype.renderTiles()
}
Game.prototype.renderTiles = function() {
// code goes here...
console.log(this.bricks) <- undefined
console.log(Game.bricks) <- undefined
}
...對於其他原型功能也是如此。
你必須顯示調用renderTiles()的代碼。 – jfriend00 2011-12-18 18:39:47