我正在调试代码,并看到在调用 erase() 时正确填充了实体和 _deferredKill 数组。问题是参数“item”没有定义,即使我看到参数“gGameEngine._deferredKill[i]”正在被传递。为什么它不接受我传递的被杀死的实体?我正在使用John Resig 的简单 javascript 继承 。
//In GameEngine.js
GameEngineClass = Class.extend({
entities: [],
_deferredKill: [],
.........
for (var k = 0; k < gGameEngine._deferredKill.length; k++){
gGameEngine.entities.erase(gGameEngine._deferredKill[i]);
}
}
gGameEngine = new GameEngineClass();
//in core.js, GameEngineClass is extended from this.
Array.prototype.erase = function(item) {
for (var i = this.length; i--; i) {
if (this[i] === item) this.splice(i, 1);
}
return this;
};