在下面的代码中:
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 中对此进行测试。