matthewkastor / object-merge

Merges JavaScript objects recursively without altering the objects merged.
16 stars 9 forks source link

maybe wrong #3

Closed qiuzuhui closed 10 years ago

qiuzuhui commented 10 years ago

I don't know if it is right in your propose ? maybe merge method is hard to fit everyone's need obj1={ a:{f:[1,2]} } obj2={ a:{f:[3]} } require('object-merge')(obj1,obj2) = { a: { f: [ 3, 2 ] } }

matthewkastor commented 10 years ago

See browser/tests for the tests. It sounds like you want to create a union of all elements in two arrays. JavaScript already does that natively. This module provides functionality not present natively. So yes, merging two arrays will create one array with matching elements in the same indexes as the original array. The last array merged in, whose value for that "slot" is defined, "wins".

Think of it like merging changes into a text file and accepting the latest changes by default.