gpt4 book ai didi

javascript - 类型错误 : Object is undefined

转载 作者:行者123 更新时间:2023-11-29 14:57:46 24 4
gpt4 key购买 nike

在下面的代码中:

var FilledObjectArray = function() {
this.filledObject = {};
};

FilledObjectArray.prototype = {
fill: function() {
this.filledObject["one"] = 1;
}
};

var SomeClass = function() {
this.something = new FilledObjectArray();
};

SomeClass.prototype = {
showContents: function() {
this.something.fill();
for (key in this.something) {
$("#some-div").append(this.something[key]);
}
}
};

$(document).ready(function() {

var s = new SomeClass();

$(".bla").each(function() {
$(this).click(function() {
s.showContents();
});
});

});

我在 Firebug 控制台中收到此错误:

TypeError: this.filledObject is undefined
this.filledObject["one"] = 1;

我在这里做错了什么?据我了解,对象已正确初始化并且赋值是正确的。我正在 Firefox 18.0.2 版本和 Chrome 25 中对此进行测试。

最佳答案

我认为这应该可以解决您的问题

this.something.fill.call(this.something);

关于javascript - 类型错误 : Object is undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15109565/

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