isObjectEqual (only for enumerable properties)

function isObjectEqual (obj1, obj2) {
  if (typeof obj1 !== 'object' || typeof obj2 !== 'object') {
  return obj1 === obj2
  }
  // if refer to the same location
  if (obj1 === obj2) {
  return true
  }

  var keys1 = Object.keys(obj1)
  var keys2 = Object.keys(obj2)

  if (keys1.length !== keys2.length) {
  return false
  }

  if (keys1.length === 0 && keys2.length === 0) {
  return true
  }

  for (var i = 0, len = keys1.length; i < len; i++) {
  if (!isObjectEqual(obj1[keys1[i]], obj2[keys2[i]])) {
    return false
  }
  }
  return true
}

 

Was this helpful?

0 / 0

发表评论 0

Your email address will not be published. Required fields are marked *