Skip to content

Instantly share code, notes, and snippets.

@aMarCruz
Created January 22, 2016 08:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aMarCruz/f5b1f511db4c1b5e4d95 to your computer and use it in GitHub Desktop.
Save aMarCruz/f5b1f511db4c1b5e4d95 to your computer and use it in GitHub Desktop.
Returns a new object with all the properties of the objects passed as parameters.
/**
* Returns a new object with all the properties of the objects passed as parameters.
* The parameters can be zero or more instances of Object or derivates.
*
* @returns {object} - Any number of objects
*/
module.exports = function xmerge () {
var target = {}
for (var i = 0; i < arguments.length; i++) {
var source = arguments[i]
if (source) {
for (var k in source) {
if (source.hasOwnProperty(k)) {
target[k] = source[k]
}
}
}
}
return target
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment