dumb_terminal
2007-Sep-10 18:09 UTC
Prototype Arrays - dont seem to hold values when i insert elemnts by name (not number)
I get a function returned with no contained values when inserting elements into an array using key''s instead of position (for example): var x = new Array(); // set ref to id of a form element... x["control_ref_1"] = "formElement1"; alert($(x["my name"]).value); If i remove the prototype js reference in my page - it works again. I have hacked around the problem to work (used Object instead of Array) - but i would like to know why it works this way. I know that prototype extends array - but is this a bug - or a specified way to work? And why? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ryan Gahl
2007-Sep-10 18:22 UTC
Re: Prototype Arrays - dont seem to hold values when i insert elemnts by name (not number)
You should just use Object. You are merely using Object''s behavior with your Array instance anyway (i.e. you are not using Array''s special features at all so why even bother creating an Array instance). Arrays should never be used as associative arrays. That''s the rule you''re looking for, I think. On 9/10/07, dumb_terminal <whiting.justin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > I get a function returned with no contained values when inserting > elements into an array using key''s instead of position (for example): > > var x = new Array(); > // set ref to id of a form element... > x["control_ref_1"] = "formElement1"; > alert($(x["my name"]).value); > > If i remove the prototype js reference in my page - it works again. I > have hacked around the problem to work (used Object instead of Array) > - but i would like to know why it works this way. I know that > prototype extends array - but is this a bug - or a specified way to > work? And why? > > > > >-- Ryan Gahl Manager, Senior Software Engineer Nth Penguin, LLC http://www.nthpenguin.com -- Architect WebWidgetry.com / MashupStudio.com Future Home of the World''s First Complete Web Platform -- Inquire: 1-262-951-6727 Blog: http://www.someElement.com --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---