Created
March 18, 2016 08:45
-
-
Save HarasimowiczKamil/23d24b1e96df393f12c4 to your computer and use it in GitHub Desktop.
Merge objects in javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Merge objects | |
* | |
* @param {...object} obj | |
* | |
* @return {object} | |
*/ | |
function merge() { | |
var i, obj, key, | |
result = {}; | |
for (i = arguments.length - 1; i >= 0; i--) { | |
obj = arguments[i]; | |
for (key in obj) { | |
if (obj.hasOwnProperty(key)) { | |
result[key] = obj[key]; | |
} | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment