Using prototype 1.6.0.2 Why does this not work? the documentation says setStyle takes a hash of property value pairs: stylehash = $H() stylehash.set(''height'', ''100px''); $(''mydiv'').setStyle(stylehash); Feeding it an old-fashioned javascript object works however: stylehash { height: ''100px'' }; $(''mydiv'').setStyle(stylehash); Is there a good reason for this, or am I fundamentally misunderstanding something? Cheers -Ralph --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Thu, Mar 20, 2008 at 11:37 AM, Ralph <ralph.sleigh-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Is there a good reason for this, or am I fundamentally > misunderstanding something?The Prototype method expects a plain old hash, not an extended Prototype one. It iterates over *each* property on the hash passed in, and in the case of an extended Prototype hash, that means all the methods on the hash object. If you have a look in prototype.js in the #setStyle method you will see the following: for (var property in styles) Where styles is the hash you pass in. Try playing around with this type of loop in your Firebug console with a basic hash object vs. a prototype extended hash. They yield quite different results. Hope this answers your question. Have a great day. -justin --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks for the quick reply. Though I would argue that this is somewhat counterintuitive and the framework should really: A) accept its own special hash if its functions ask for a hash or B) make its clearer in the documentation that the function requires a vanilla hash. -Ralph --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ralph, This is clearly a documentation bug. The description should state that "values" parameter expects object (#setStyle will actually take anything and simply iterate over it - producing unexpected results). On the other hand, examples show the proper usage. #setStyle could actually try to play nice with Hash instances, but I''m afraid it''s more of an edge case and is not worth extra complexity. Best, kangax On Mar 20, 1:36 pm, Ralph <ralph.sle...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks for the quick reply. > > Though I would argue that this is somewhat counterintuitive and the > framework should really: > > A) accept its own special hash if its functions ask for a hash > or > B) make its clearer in the documentation that the function requires a > vanilla hash. > > -Ralph--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---