Yes it''s true that Prototype will mess up when using for..in loops on
Arrays, but you should never do that anyway.
Use a regular for-loop (for (var i = 0, length = myArray.length; i <
length; i++) {..} or Prototype''s #each, #map etc for looping over
arrays.
You are safe to use for..in loops on Objects, in fact, a lot of
Prototype''s internal code uses this method(s).
Read more:
<http://andrewdupont.net/2006/05/18/javascript-associative-arrays-considered-harmful/>
Martin
On 03/10/2007, Rob <raldred-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
> There seems to be some sort of conflict with prototype and the for
> "in" operator.
>
> var f = new
Array(''value1'',''value2'',''value3'');
> for(g in f)
> {
> alert(g);
> }
>
> Fine?
> Well, with prototype loaded, both IE + FF get an extra alert...
>
> IE gets it before the values in the array:
>
http://s44.photobucket.com/albums/f42/raldred/?action=view¤t=forin-ie.gif
>
> FF gets it after the other values in the array:
>
http://s44.photobucket.com/albums/f42/raldred/?action=view¤t=forin-ff.gif
>
>
> Does anyone have any solution to this?
> Or do i just have to annoying method of
> for(var i=0;i<f.length;i++)
> {
> alert(f[i]);
> }
>
> Thanks
> Rob
>
>
> >
>
--
burnfield.com/martin
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---