Skip to content

Instantly share code, notes, and snippets.

@jeremyckahn
Created June 2, 2014 16:07
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 jeremyckahn/0aafbea72656bee23144 to your computer and use it in GitHub Desktop.
Save jeremyckahn/0aafbea72656bee23144 to your computer and use it in GitHub Desktop.
Merge two objects, similar to $.extend(true). Requires underscore.js.
function mergeObjects (target, source) {
var prop;
for (prop in source) {
if (source.hasOwnProperty(prop)) {
if (_.isObject(target[prop]) && _.isObject(source[prop])) {
mergeObjects(target[prop], source[prop]);
} else {
target[prop] = source[prop];
}
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment