1 | 'use strict';
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | function merge() {
|
14 | var objects = Array.prototype.slice.call(arguments);
|
15 | var target = objects.shift();
|
16 | if(typeof target !== 'object' || Array.isArray(target)) {
|
17 | return;
|
18 | }
|
19 | objects.forEach(function(o) {
|
20 | if(typeof o === 'object') {
|
21 | Object.getOwnPropertyNames(o).forEach(function(n) {
|
22 | var v;
|
23 | if(Array.isArray(o[n])) {
|
24 | v = o[n].slice();
|
25 | } else if(typeof o[n] === 'object') {
|
26 | v = merge({}, o[n]);
|
27 | } else {
|
28 | v = o[n];
|
29 | }
|
30 | target[n] = v;
|
31 | });
|
32 | }
|
33 | });
|
34 | return target;
|
35 | }
|
36 |
|
37 | module.exports = merge; |
\ | No newline at end of file |