gpt4 book ai didi

IE8 中的 Javascript "Member not found"错误

转载 作者:行者123 更新时间:2023-11-29 18:36:43 25 4
gpt4 key购买 nike

我正在尝试调试以下 Javascript 代码块以查看问题所在。我在

constructor = function() {
in the extend:function() method.

I'm not very good with Javascript, and I didn't write this, so I'm kind of lost on what the issue is. The error only occurs in IE8, it works fine in IE7 and 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;
}
}
行收到一条错误消息,显示“找不到成员”

最佳答案

我看到的一个直接问题是“构造函数”是一个全局变量。使用 "var constructor = function..."给它局部作用域。

关于IE8 中的 Javascript "Member not found"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2501054/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com