【发布时间】:2009-11-24 16:38:42
【问题描述】:
为什么会...
for(var k in this.errors) {
$('error_list').insert({
bottom: new Element('li').update(k + ' :'+this.errors[k])
})
}
...输出把所有的 Prototype 可枚举的方法,加上我添加到数组中的东西?
我正在构建一个关联数组:
this.errors['email'] = 'Your email is invalid';
【问题讨论】:
-
JavaScript 没有真正的关联数组。您正在设置数组的属性(这是合法的),但 JavaScript 没有用于这种用法的特殊方法。为此目的,最好使用对象而不是数组。
标签: javascript arrays prototype