Created
October 1, 2017 08:06
-
-
Save tkssharma/f23eacf70563554332d263866b627973 to your computer and use it in GitHub Desktop.
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
function assignDeep(target, ...sources) { | |
for (let source of sources) { | |
for (let key in source) { | |
if (isObject(source[key])) { | |
if (!isObject(target[key])) { | |
target[key] = {} | |
} | |
assignDeep(target[key], source[key]) | |
} else { | |
target[key] = source[key] | |
} | |
} | |
} | |
return target | |
} | |
function isObject(a) { | |
return typeof a === 'object' && a !== null | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment