什么是;无法读取属性'_肮脏';“未定义”的定义;什么意思?(Enchant.js/Javascript)
我正在为一个大学项目使用“Enchant.js”javascript框架制作一个游戏,收到了这个错误(导致游戏冻结)。我甚至不知道“脏”是什么意思,我想我完全不懂。(我在谷歌上搜索了“_dirty”,知道它指的是“未保存的更改”,但我不完全确定这是什么意思。) 非常感谢您的帮助什么是;无法读取属性'_肮脏';“未定义”的定义;什么意思?(Enchant.js/Javascript),javascript,Javascript,我正在为一个大学项目使用“Enchant.js”javascript框架制作一个游戏,收到了这个错误(导致游戏冻结)。我甚至不知道“脏”是什么意思,我想我完全不懂。(我在谷歌上搜索了“_dirty”,知道它指的是“未保存的更改”,但我不完全确定这是什么意思。) 非常感谢您的帮助 var Meds = Class.create(Sprite, { //Two argument constructor takes in X and Y co-ordinate for patient
var Meds = Class.create(Sprite,
{
//Two argument constructor takes in X and Y co-ordinate for patient
initialize: function(x,y)
{
//Inherit all enchant.Sprite properties using it's constructor
Sprite.apply(this, [16,16]);
//Set image and co-ordinates for meds
this.image = Game.instance.assets['art/icon0.gif'];
this.frame = 13;
this.x = x;
this.y = y;
//Add medicine to 'scene' group
scene.addChild(this);
},
//Function for removing medicine
remove: function()
{
//Remove from 'scene' group
scene.removeChild(this);
//Delete med from array
delete meds[this.key];
//Delete med from memory
delete this;
//Decrement counter variable
currentMedAmount--;
}
});
game.rootScene.addEventListener('enterframe', function()
{
for(var i=0; i < meds.length; i++)
{
if(sally.within(meds[i], 35) && game.input.Z_BUTTON)
{
meds[i].remove();
console.log('WORKING!');
}
}
});
var Meds=Class.create(精灵,
{
//双参数构造函数接受患者的X和Y坐标
初始化:函数(x,y)
{
//使用其构造函数继承所有enchant.Sprite属性
应用(这个[16,16]);
//为MED设置图像和坐标
this.image=Game.instance.assets['art/icon0.gif'];
此帧=13;
这个.x=x;
这个。y=y;
//将药物添加到“场景”组
场景。addChild(本);
},
//除药功能
删除:函数()
{
//从“场景”组中删除
场景。removeChild(本);
//从数组中删除med
删除药物[this.key];
//从内存中删除med
删除此项;
//减量计数器变量
当前金额--;
}
});
game.rootScene.addEventListener('enterframe',function())
{
对于(变量i=0;i
这意味着某些代码试图使用字符串“\u dirty”通过一个实际上不是引用的引用来引用属性。类似于foo.\u dirty
或foo[key]
其中“key”是“\u dirty”,而“foo”是未定义的。为什么?1000种可能性。如果错误来自框架内部,请使用未缩小的版本,以便更易于调试。感谢您的及时回复,但我没有使用缩小的版本,并且短语“\u dirty”不在我的代码中的任何位置,也没有任何对“未定义”对象的引用(据我所知)我在其他地方引用了代码中的所有内容,完全没有错误,这让我不知所措。浏览器开发人员工具应该向您显示与错误相关的堆栈跟踪。这将有助于弄清发生了什么。问题很可能是您的代码所做的事情超出了库的预期。大多数面向浏览器的JavaScript库几乎没有错误检查代码,因此当出现问题时,您不会得到明确的解释。请注意,Enchant.js代码到处都使用属性名“\u dirty”。