function isEqual(obj1,obj2) {
// 如果有一个不是对象,直接对比
if(!(typeof obj1 === 'object' && typeof obj1 !==null) || !(typeof obj2 === 'object' && typeof obj2 !==null)) {
return obj1 === obj2;
}
if(obj1 === obj2) {
return true;
}
const obj1Keys = Object.keys(obj1);
const obj2Keys = Object.keys(obj1);
if(obj1Keys.length !== obj2Keys.length) {
return false;
}
for(let key in obj1) {
const res = isEqual(obj1[key],obj2[key]); // 递归比较
if(!res) {
return false;
}
}
return true;
}