Skip to content

Instantly share code, notes, and snippets.

@VividVisions
Forked from padolsey/gist:272905
Created August 31, 2014 22:10
Show Gist options
  • Save VividVisions/ccbbceb69be0f5bea307 to your computer and use it in GitHub Desktop.
Save VividVisions/ccbbceb69be0f5bea307 to your computer and use it in GitHub Desktop.
function merge(target, source) {
/* Merges two (or more) objects,
giving the last one precedence */
if ( typeof target !== 'object' ) {
target = {};
}
for (var property in source) {
if ( source.hasOwnProperty(property) ) {
var sourceProperty = source[ property ];
if ( typeof sourceProperty === 'object' ) {
target[ property ] = util.merge( target[ property ], sourceProperty );
continue;
}
target[ property ] = sourceProperty;
}
}
for (var a = 2, l = arguments.length; a < l; a++) {
merge(target, arguments[a]);
}
return target;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment