Proposal: Object.equals and hashCode

Proposal: https://github.com/tc39/proposal-object-equals`

Implement the ability to compare objects based on content as in Java

  • add hashable option to data descriptor of objects (if the property is to be used in hash calculation. All own properties by default)
  • add hashCode to object instances
  • add equals to object prototype
  • use fast algorithm to calculate hashCode of objects, arrays etc. (based on hash of own properties and hashes of nested objects)

object1.equals(object2) or Object.equals(object1, object2)

FYI you've got an errant ` at the end of your proposal link.

Adding new things to Object.prototype isn't likely to fly, and wouldn't work for null objects anyways.

Related proposals that already exist:

I'd be opposed to manually computed hashcodes, but @aclaymore has an idea for composite keys that would likely subsume this need

1 Like