TehShrike / deepmerge

A library for deep (recursive) merging of Javascript objects
MIT License
2.75k stars 216 forks source link

Don't mutate the options object #166

Closed TehShrike closed 4 years ago

TehShrike commented 4 years ago

right now if you pass in an options object, and you don't specify any of the optional properties, the code just assigns those properties on the object you passed in. This is rude and just poor form in general.

The easiest way that comes to mind to fix this would be to wait until #161 and then use the object spread syntax to combine the input options and a default options object into a new object.

macdja38 commented 4 years ago
    options = Object.assign({}, { arrayMerge: defaultArrayMerge , isMergeableObject: defaultIsMergeableObject }, options)

Would do pretty much the same thing but without requiring es6, at the cost of a few more characters.

TehShrike commented 4 years ago

Yeah, that would work. If anyone wants to do that in the near future we can put it out as a feature release before 5.0.0

TehShrike commented 4 years ago

Published as 4.1.1

TehShrike commented 4 years ago

Whoops, switching to Object.assign breaks support for IE11. I'll move this change over to the v5 branch.