Object.prototype.isEquals = function(obj){
if (this === obj) return true
let thisProps = Object.keys(this)
let objProps = Object.keys(obj)
if (thisProps.length !== objProps.length) return false
for (let prop in this) {
if (!this.hasOwnProperty(prop))continue;
if (obj.hasOwnProperty(prop)) {
if (this[prop] instanceof Object || this[prop] instanceof Array) {
if (!this[prop].isEquals(obj[prop])) return false
} else if (this[prop] !== obj[prop]) {
return false
}
} else {
return false
}
}
return true
}
进一步优化,判断对象是否相等