millermedeiros / amd-utils

modular JavaScript utilities written in the AMD format
http://millermedeiros.github.com/amd-utils
142 stars 11 forks source link

Add object/deepMixIn #95

Closed conradz closed 12 years ago

conradz commented 12 years ago

This adds a method that works like jQuery's extend method with the first parameter true to specify the deep copy.

Not totally sure about the name, it could be a mutating object/merge or a deep copying object/mixIn method. It is closest to object/mixIn in the code, though.

millermedeiros commented 12 years ago

mixIn doesn't clone the properties it just copy the references, so I think this implementation is closer to object/merge.

$.extend(true, foo, bar); also doesn't clone the properties, it just overwrites the members of all arrays/objects. I think we should match jQuery behavior for the deepMixIn method.

Do think we need a mutating object/merge? I feel it's redundant if we have a deepMixIn.

Thanks for all the good feedback and pull requests!

conradz commented 12 years ago

OK, I changed object/deepMixIn to not clone child objects. My use case didn't really matter if we don't clone the child objects, I had just put it in because object/merge had it. Didn't see that jQuery.extend didn't have it, though. I'm using this to receive incremental updates from the server in JSON format, and update the existing data on the client.

millermedeiros commented 12 years ago

@conradz I updated it to also merge arrays, matching the $.extend(true) behavior. Thanks once again.