Closed lerayne closed 7 years ago
Any updates here?
@lerayne @mandrichenko I'm not sure if it is a bug, and this behavior might not be obvious for you but I think it's correct. Look, you specify target object in first argument which one you want to extend, not to clone, just extend (if you want to clone it you specify new empty object as first argument like this deepExtend({}, foo, bar)
, so, it is not supposed to be cloning any branches, just add or replace some values, and it doesn't care about if some branch is the same object as another branch.
In your case you expect it to be cloned, so, correct usage would be:
config = deepExtend({}, {...configDefaults}, config)
And keep in mind when you writing in javascript that spread-operator do cloning just on the same level, skipping any child-object branches.
I just added a test to demonstrate it: https://github.com/unclechu/node-deep-extend/commit/ffe04c39a4d0c58044789592fe7b686a3bfe44b5
Example:
original object, two fields,
fontValueTitle
andfontValueSubitle
are pointing to one objectthen I'm doning this:
and the output is