# Proposal: Object.equals and hashCode

**URL:** <https://es.discourse.group/t/proposal-object-equals-and-hashcode/1753>\
**Category:** 🦋 Proposals\
**Tags:** proposal\
**Created:** [July 18, 2023, 1:49pm UTC](https://es.discourse.group/t/proposal-object-equals-and-hashcode/1753 "2023-07-18T13:49:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tamtakoe](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/tamtakoe/32/1805_2.png) [@tamtakoe](https://es.discourse.group/u/tamtakoe)\
**Post date:** [July 18, 2023, 1:49pm UTC](https://es.discourse.group/t/proposal-object-equals-and-hashcode/1753/1 "2023-07-18T13:49:58Z")

</div>

#### Proposal: [https://github.com/tc39/proposal-object-equals`](https://github.com/tc39/proposal-object-equals%60)

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)`

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/senocular/32/642_2.png) [@senocular](https://es.discourse.group/u/senocular)\
**Post date:** [July 18, 2023, 2:18pm UTC](https://es.discourse.group/t/proposal-object-equals-and-hashcode/1753/2 "2023-07-18T14:18:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ljharb](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ljharb/32/8_2.png) [@ljharb](https://es.discourse.group/u/ljharb)\
**Post date:** [July 18, 2023, 4:03pm UTC](https://es.discourse.group/t/proposal-object-equals-and-hashcode/1753/3 "2023-07-18T16:03:51Z")

</div>

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

Related proposals that already exist:

- [https://github.com/sebmarkbage/ecmascript-shallow-equal](https://github.com/sebmarkbage/ecmascript-shallow-equal)
- [https://github.com/tc39/proposal-array-equality](https://github.com/tc39/proposal-array-equality)
- [https://github.com/tc39/proposal-record-tuple](https://github.com/tc39/proposal-record-tuple)

---

<div class="post-metadata">

**Author:** ![mhofman](https://avatars.discourse-cdn.com/v4/letter/m/f14d63/32.png) [@mhofman](https://es.discourse.group/u/mhofman)\
**Post date:** [July 20, 2023, 5:17am UTC](https://es.discourse.group/t/proposal-object-equals-and-hashcode/1753/4 "2023-07-20T05:17:02Z")

</div>

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