unclechu / node-deep-extend

Recursive extend module
MIT License
202 stars 53 forks source link

How to extend array-type values using override insteadof concat? #18

Closed dickeylth closed 9 years ago

dickeylth commented 9 years ago
var extendedObj = deepExtend({
    a: [1,2,3]
}, {
    a: [2,3]
});
console.log(extendedObj);
// { a: [ 2, 3, 3 ] }, however in my situation I expect { a: [ 2, 3 ] }

It seems that deep-extend uses replacement by index in array and concat two arrays, however in my situation I want to override the first array value, how to do that?

ninjatux commented 9 years ago

@dickeylth not sure if this should be a functionality for a function like "deep extend", otherwise you are making the function aware about the content of the array.

unclechu commented 9 years ago

@dickeylth now it follows jQuery.extend() style, and jQuery do extend arrays like that:

$.extend([1,2,3], [2,3])
Array [ 2, 3, 3 ]
unclechu commented 9 years ago

May be it's time to create some custom module without arrays extending.

unclechu commented 9 years ago

@dickeylth oh, it's looks like it isn't whole picture, jQuery overwrite arrays if they inside objects:

$.extend({a: [1, 2, 3]}, {a: [2, 3]}).a
Array [ 2, 3 ]
unclechu commented 9 years ago

Fixed by 9ea374c54bdff7e42be163ae09670ea8cf3bbc7e

dickeylth commented 9 years ago

Cool!~Thank you!