1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| var a={a:{b:{c:1}},b:2,c:3},b={a:{e:2},b:{}}; var util={ type:{ Object:'[object Object]', Undefined:'[object Undefined]' }, judge:function(d,t){return Object.prototype.toString.call(d)===this.type[t]}, isUndefined:function(d){return this.judge(d,'Undefined')}, isObject:function(d){return this.judge(d,'Object')}, isArray:function(d){return Array.isArray(d)}, mergeJson:function(oa,ob){ if(!util.isObject(oa)||!util.isObject(ob)){ return ob } for(var i in oa){ if(util.isUndefined(ob[i])){ ob[i]=oa[i] } if(util.isObject(oa[i]) && util.isObject(ob[i])){ util.mergeJson(oa[i],ob[i]) } if(util.isArray(oa[i])&&util.isArray(ob[i])){ ob[i].concat(oa[i]) } } return ob; } } const merge=util.mergeJson; const result=merge(a,b)
|