Created
January 24, 2017 14:27
-
-
Save jonathantneal/24150d6a5a392291e87de9029cfbe25e to your computer and use it in GitHub Desktop.
Object Deep Assign
This file contains 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 isObject = (item) => Object(item) === item && !Array.isArray(item); | |
const deepAssign = module.exports = (target, ...sources) => { | |
sources.forEach( | |
(source) => { | |
Object.keys(source).map( | |
(key) => { | |
target[key] = isObject(target[key]) && isObject(source[key]) ? deepAssign(target[key], source[key]) : source[key]; | |
} | |
) | |
} | |
); | |
return target; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment