我正在重复使用旧的应用程序(游戏),因此可以运行几个游戏。 由于这个原因,我已经将属性更改为“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