First of all, is not the same as forEach.
In second place, iterating arrays with `` is just stupid, it is meant
to be used with objects in general. It's well known that `` is
extremely inefficient when compared to length-cached `for` loops.
So, you should be doing

var foo = [1,2,3];
for(var i = 0, len = foo.length; i < len; ++i)
  //do stuff with foo[i]

If you take a look at what the `` statement does[1], you should see
that it iterates over all the object's properties, but not only his own,
also the ones that he inherits from his constructor's prototype property.
That's why you see all the Array[2] methods when you iterate a
prototype-extended array with ``.


Gabriel Gilini

On Fri, May 1, 2009 at 3:35 PM, GlennFleishman <> wrote:

> I checked back discussions and I don't see this addressed. There's a
> collision between Prototype and certain kinds of array calls as
> documented at
> I saw this behavior on my site when I added an Amazon product pop-up
> JavaScript that apparently makes a "for (var foo in array)" call. I've
> notified Amazon as to the problem, in case they can fix it easily on
> their end to avoid the collision.
> In my case, I saw millions of queries made to my site that look like
> this:
> "GET /function%20(filter,%20iter
> ator,%20context)%20%7B%20%20%20%20iterator%20=%20iterator%20?
> %20iterator.bind(context)%20:%20Prototype.K;%20%2
> 0%20%20var%20results%20=%20[];%20%20%20%20if%20(Object.isString
> (filter))%20{%20%20%20%20%20%20%20%20filter%20=
> %20new%20RegExp(filter);%20%20%20%20}%20%20%20%20this.each(function%20
> (value,%20index)%20{if%20(filter.match(v
> alue))%20{results.push(iterator(value,%20index));}});%20%20%20%20return
> %20results;} HTTP/1.1"
> >

You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

Reply via email to