|
|
@@ -62,10 +62,13 @@ export const diff = (obj1, obj2) => { |
|
|
|
var o1 = obj1 instanceof Object |
|
|
|
var o2 = obj2 instanceof Object |
|
|
|
if (!o1 || !o2) { /* 判断不是对象 */ |
|
|
|
// console.log(1); |
|
|
|
return obj1 === obj2 |
|
|
|
} |
|
|
|
|
|
|
|
if (Object.keys(obj1).length !== Object.keys(obj2).length) { |
|
|
|
// console.log(2); |
|
|
|
console.log(Object.keys(obj1).length,Object.keys(obj2).length); |
|
|
|
return false |
|
|
|
// Object.keys() 返回一个由对象的自身可枚举属性(key值)组成的数组,例如:数组返回下表:let arr = ["a", "b", "c"];console.log(Object.keys(arr))->0,1,2; |
|
|
|
} |
|
|
@@ -74,11 +77,15 @@ export const diff = (obj1, obj2) => { |
|
|
|
var t1 = obj1[attr] instanceof Object |
|
|
|
var t2 = obj2[attr] instanceof Object |
|
|
|
if (t1 && t2) { |
|
|
|
// console.log(3); |
|
|
|
return diff(obj1[attr], obj2[attr]) |
|
|
|
} else if (obj1[attr] !== obj2[attr]) { |
|
|
|
// console.log(obj1[attr],obj2[attr]); |
|
|
|
// console.log(4); |
|
|
|
return false |
|
|
|
} |
|
|
|
} |
|
|
|
// console.log(5); |
|
|
|
return true |
|
|
|
} |
|
|
|
/** |
|
|
|