Created
March 8, 2021 23:54
-
-
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
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
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