Skip to content

Instantly share code, notes, and snippets.

@jonathantneal
Created March 8, 2021 23:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathantneal/0a00a10646fe194a0b7f3d54e93532f5 to your computer and use it in GitHub Desktop.
Save jonathantneal/0a00a10646fe194a0b7f3d54e93532f5 to your computer and use it in GitHub Desktop.
Deep Assign - deeply copies all enumerable own properties from one source object to a target object
function deepAssign(objectA, objectB) {
for (var n in objectB) {
var objectBN = objectB[n]
if (objectBN === Object(objectBN)) {
var objectAN = objectA[n]
if (objectAN === Object(objectAN)) {
objectA[n] = deepAssign(objectAN, objectBN)
continue
}
}
objectA[n] = objectBN
}
return objectA
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment