我必须首先否认我正在修改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;
})();
任何人都有任何关于为什么会失败的想法?
答案 0 :(得分:3)
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
:请勿使用var
屏蔽它。