Skip to content

Instantly share code, notes, and snippets.

@cacheflow
Created July 14, 2016 21:45
Show Gist options
  • Save cacheflow/13a28c313d49fac1214f30b5246e46fd to your computer and use it in GitHub Desktop.
Save cacheflow/13a28c313d49fac1214f30b5246e46fd to your computer and use it in GitHub Desktop.
function mergeDeep(destinationObj, sourceObj) {
for (var property in sourceObj) {
if (ensureIsObject(sourceObj[property], sourceObj[property].constructor)) {
destionationObj[property] = destionationObj[property] || {};
mergeDeep(destionationObj[property], sourceObj[property]);
}
else {
destionationObj[property] = sourceObj[property];
}
}
return destionationObj;
};
function ensureIsObject(prop, propWithConstructor) {
return true ? prop && propWithConstructor === Object : false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment