Created
October 8, 2013 15:23
-
-
Save MathieuLoutre/6886442 to your computer and use it in GitHub Desktop.
Merge two JS objects
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 merge (obj, source) { | |
for (prop in source) { | |
if (typeof source[prop] === 'object' && typeof obj[prop] === 'object') { | |
merge(obj[prop], source[prop]) | |
} | |
else { | |
if (obj[prop] === void 0) { | |
obj[prop] = source[prop] | |
} | |
} | |
} | |
return obj | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment