[解决]
从事件监听器调用newGame
函数,以便this
引用事件调用者
目前我遇到了这个烦人的问题,我正在创建一个游戏,其中特定游戏的所有变量都存储在Game()
类/函数/对象中,并且{{1创建初始游戏并具有创建新游戏的功能。
问题是,我无法覆盖newGame函数中的初始游戏,这里是:
GameManager
运行var GameManager = {};
GameManager.currentGame = null;
GameManager.init = function() {
this.newGame();
}
GameManager.newGame = function() {
this.currentGame = new Game();
}
GameManager.init();
函数后,结果为:
newGame
为了把事情放得更简单,我在这里使用了GameManager.currentGame == the original game, NOT the new one.
:
int
运行var GameManager = {};
GameManager.currentGame = null;
GameManager.init = function() {
this.currentGame = 12;
}
GameManager.newGame = function() {
this.currentGame = 0;
}
GameManager.init();
函数后,结果为:
newGame
(不是0,正如预期的那样)
我觉得这是对象引用或类似事件的一个明显问题,我很感激所有回复!
由于