Skip to content

Instantly share code, notes, and snippets.

@MathieuLoutre
Created October 8, 2013 15:23
Show Gist options
  • Save MathieuLoutre/6886442 to your computer and use it in GitHub Desktop.
Save MathieuLoutre/6886442 to your computer and use it in GitHub Desktop.
Merge two JS objects
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