在下面的代码中:
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/