Skip to content

Instantly share code, notes, and snippets.

@aMarCruz

aMarCruz/xmerge.js

Created Jan 22, 2016
Embed
What would you like to do?
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