UNPKG

785 BJavaScriptView Raw
1var forOwn = require('./forOwn');
2
3 /**
4 * Combine properties from all the objects into first one.
5 * - This method affects target object in place, if you want to create a new Object pass an empty object as first param.
6 * @param {object} target Target Object
7 * @param {...object} objects Objects to be combined (0...n objects).
8 * @return {object} Target Object.
9 */
10 function mixIn(target, objects){
11 var i = 0,
12 n = arguments.length,
13 obj;
14 while(++i < n){
15 obj = arguments[i];
16 if (obj != null) {
17 forOwn(obj, copyProp, target);
18 }
19 }
20 return target;
21 }
22
23 function copyProp(val, key){
24 this[key] = val;
25 }
26
27 module.exports = mixIn;
28