同属性对象属性值对比
isObject(obj){
return obj !== null && typeof obj === 'object'
}
compareDiff(a,b){
var isObjectRes = this.isObject(a) && this.isObject(b)
var isArrayRes = Array.isArray(a) && Array.isArray(b)
let res
if(isArrayRes){
res = []
a.map((item,index)=>{
retrun (res[index] = this.compareDiff(item, b[index]))
})
}
if(isObjectRes && !isArrayRes){
res = {}
Object.keys(a).map(key => {
if(this.isObject(a[key]) && this.isObject(b[key])) {
return (res[key] = this.compareDiff(a[key], b[key]))
}else {
res[key] = a[key] === b[key]
}
})
return res
}
if(!isObjectRes && !isArrayRes){
return a === b
}
return res
}