我必须首先声明我要修改Game Dev Tycoon,但是游戏的源代码是事先运行的,因此在运行此代码之前将“ Game”对象放置在全局范围内。
new Game({
conferenceHype: 0
}).gameSize; /* proves that it exists */
(function() {
var Game, oldGame, oldGameConst;
oldGameConst = Game;
oldGame = oldGameConst.prototype; /* fails here because it thinks oldGameConst is undefined */
Game = function(company) {
oldGameConst.call(this, company);
this.company = company;
};
Game.prototype = oldGame;
})();
有人对为什么会失败有任何想法吗?
最佳答案
var Game, oldGame, oldGameConst;
oldGameConst = Game;
oldGame = oldGameConst.prototype; /* fails here because it thinks oldGameConst is undefined */
那么你:
创建一些局部变量,所有局部变量均以
undefined
开头将
Game
的值(因为您刚刚声明,所以将其复制到undefined
)出于上述原因,请尝试阅读
oldGameConst
…,它是oldGameConst.prototype
。如果要从更广泛的范围访问
undefined
:请勿使用Game
对其进行屏蔽。