views:

63

answers:

3

Why would...

for(var k in this.errors) {
  $('error_list').insert({
   bottom: new Element('li').update(k + ' :'+this.errors[k])
  })
 }

...output put all Prototype enumerable methods, plus what I've added to the array?

I'm building an associative array:

this.errors['email'] = 'Your email is invalid';
+2  A: 

You need to use "hasOwnProperty" to guard against this.

Matthew Wilson
+1  A: 

Try this:

$H(this.errors).each(function(error) {
 $('error_list').insert({
  bottom: new Element('li').update(error.key + ': ' + error.value)
 })
})
Alexander Malfait
+2  A: 

You may prevent this using hasOwnProperty:

for(var k in this.errors) {
    if (this.errors.hasOwnProperty(k)) {
        $('error_list').insert({
            bottom: new Element('li').update(k + ' :'+this.errors[k])
        })
    }
}
stefpet