Why does Object.extend() dont extend nested keys/values... var obj = { item_1:''abc'', item_2:{ item_2a:''123'', item_2b:''456'' }, item_3:''def'' }; alert(obj.item_2.item_2a); //123 alert(obj.item_2.item_2b); // 456 Object.extend(obj, {item_2:{item_2a:''new nested value''}}); alert(obj.item_2.item_2a); // new nested value alert(obj.item_2.item_2b) //undefined (should be "456") Last alert gives an unexpected result. Roland, --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Roland a écrit :> Why does Object.extend() dont extend nested keys/values...Because deep copy is not the general need, I guess. I, for one, never need it, and apparently the other members of Prototype Core don''t need it much, either. Personally, I also find deep copy in the JS world can often be "dangerous" to unsuspecting developers, in that many use cases could yield major slowdowns or turn out infeasible (e.g. props referencing DOM nodes or native JS objects that don''t take kindly to being cloned, etc.). However, do note that if you absolutely need deep copy, you can pretty easily monkeypatch the library with a *wrap* call. -- Christophe Porteneuve aka TDD tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Roland, take a look at this patch http://dev.rubyonrails.org/ticket/11089 - kangax On Apr 3, 3:21 am, Roland <franssen.rol...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Why does Object.extend() dont extend nested keys/values... > > var obj = { > item_1:''abc'', > item_2:{ > item_2a:''123'', > item_2b:''456'' > }, > item_3:''def'' > > }; > > alert(obj.item_2.item_2a); //123 > alert(obj.item_2.item_2b); // 456 > > Object.extend(obj, {item_2:{item_2a:''new nested value''}}); > > alert(obj.item_2.item_2a); // new nested value > alert(obj.item_2.item_2b) //undefined (should be "456") > > Last alert gives an unexpected result. > > Roland,--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---