Created
January 28, 2018 22:23
-
-
Save ycmjason/477c71fa424edbfb5c255aa5e97924ef to your computer and use it in GitHub Desktop.
Deep version of Object.assign.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const objectAssignDeep = (...objs) => objs.reduce((acc, obj) => Object.assign(acc, ...Object.keys(obj).map(key => { | |
if (acc[key] instanceof Object && obj[key] instanceof Object) { | |
return { [key]: objectAssignDeep({}, acc[key], obj[key]) }; | |
} | |
return { [key]: obj[key] }; | |
}))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example:
Note that this function has the same characteristic as Object.assign, the first object will be mutated and the rest remains.