Skip to content

Instantly share code, notes, and snippets.

@tkssharma
Created October 1, 2017 08:06
Show Gist options
  • Save tkssharma/f23eacf70563554332d263866b627973 to your computer and use it in GitHub Desktop.
Save tkssharma/f23eacf70563554332d263866b627973 to your computer and use it in GitHub Desktop.
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