我試圖調試下面的Javascript代碼塊,看看問題是什麼。在extend:function()方法中,我收到一條錯誤,指出在IE8中使用Javascript「找不到會員」錯誤
constructor = function() {行中的「找不到成員」。
我對Javascript的使用不太好,而且我沒有寫這個,所以我對這個問題感到迷茫。該錯誤只發生在IE8中,它在IE7和Firefox中正常工作。
var Class = {
create: function() {
return function() {
if(this.destroy) Class.registerForDestruction(this);
if(this.initialize) this.initialize.apply(this, arguments);
}
},
extend: function(baseClassName) {
constructor = function() {
var i;
this[baseClassName] = {}
for(i in window[baseClassName].prototype) {
if(!this[i]) this[i] = window[baseClassName].prototype[i];
if(typeof window[baseClassName].prototype[i] == 'function') {
this[baseClassName][i] = window[baseClassName].prototype[i].bind(this);
}
}
if(window[baseClassName].getInheritedStuff) {
window[baseClassName].getInheritedStuff.apply(this);
}
if(this.destroy) Class.registerForDestruction(this);
if(this.initialize) this.initialize.apply(this, arguments);
}
constructor.getInheritedStuff = function() {
this[baseClassName] = {}
for(i in window[baseClassName].prototype) {
if(!this[i]) this[i] = window[baseClassName].prototype[i];
if(typeof window[baseClassName].prototype[i] == 'function') {
this[baseClassName][i] = window[baseClassName].prototype[i].bind(this);
}
}
if(window[baseClassName].getInheritedStuff) {
window[baseClassName].getInheritedStuff.apply(this);
}
}
return constructor;
},
objectsToDestroy : [],
registerForDestruction: function(obj) {
if(!Class.addedDestructionLoader) {
Event.observe(window, 'unload', Class.destroyAllObjects);
Class.addedDestructionLoader = true;
}
Class.objectsToDestroy.push(obj);
},
destroyAllObjects: function() {
var i,item;
for(i=0;item=Class.objectsToDestroy[i];i++) {
if(item.destroy) item.destroy();
}
Class.objectsToDestroy = null;
}
}
那麼你知道嗎,就是這樣!非常感謝。 – Steven 2010-03-23 15:33:09