mirror of
https://github.com/tenrok/axios.git
synced 2026-05-30 15:24:11 +03:00
28 lines
727 B
JavaScript
28 lines
727 B
JavaScript
var forEach = require('./forEach');
|
|
|
|
/**
|
|
* Accepts varargs expecting each argument to be an object, then
|
|
* immutably merges the properties of each object and returns result.
|
|
*
|
|
* When multiple objects contain the same key the later object in
|
|
* the arguments list will take precedence.
|
|
*
|
|
* Example:
|
|
*
|
|
* ```js
|
|
* var result = merge({foo: 123}, {foo: 456});
|
|
* console.log(result.foo); // outputs 456
|
|
* ```
|
|
*
|
|
* @param {Object} obj1 Object to merge
|
|
* @returns {Object} Result of all merge properties
|
|
*/
|
|
module.exports = function merge(obj1/*, obj2, obj3, ...*/) {
|
|
var result = {};
|
|
forEach(arguments, function (obj) {
|
|
forEach(obj, function (val, key) {
|
|
result[key] = val;
|
|
});
|
|
});
|
|
return result;
|
|
}; |