# Symbol.equal - a way to define the weak equals operator on objects

**URL:** <https://es.discourse.group/t/symbol-equal-a-way-to-define-the-weak-equals-operator-on-objects/2651>\
**Category:** 💡 Ideas\
**Created:** [September 12, 2026, 4:43pm UTC](https://es.discourse.group/t/symbol-equal-a-way-to-define-the-weak-equals-operator-on-objects/2651 "2026-09-12T16:43:25Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![aclaymore](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/aclaymore/32/501_2.png) [@aclaymore](https://es.discourse.group/u/aclaymore)\
**Post date:** [September 13, 2026, 1:26am UTC](https://es.discourse.group/t/symbol-equal-a-way-to-define-the-weak-equals-operator-on-objects/2651/2 "2026-09-13T01:26:11Z")

</div>

Some previous related discussions:

> [@Symbol.equal protocol](https://es.discourse.group/t/symbol-equal-protocol/594):
>
> class Sample { constructor(value) { this.#internal = value } [Symbol.equal](input) { if (input instanceof Sample) { return this.#internal === input.#internal } return false } } const foo = new Sample(1) const bar = new Sample(1) foo === bar // here change `Strict Equality Comparison` semantics? Object.is(foo, bar) // ? // or new grammar? References: [ECMAScript® 2024 Language&nbsp;Specification](https://tc39.es/ecma262/#sec-object.is)[ECMAScript® 2024 Language&nbsp;Specification](https://tc39.es/ecma262/#sec-strict-equality-comparison)[ECMAScript® 202…](https://tc39.es/ecma262/#sec-abstract-equality-comparison)

> <https://github.com/tc39/proposal-array-equality/issues/6>
>
> I feel this is ripe for a symbol that allows extending and modifying the equalit…y check. Library precedent is rather lacking (unless you consider \[Fantasy Land's Setoid spec\](https://github.com/fantasyland/fantasy-land#setoid) and its implementers as precedent), but there is a common \`.equals\` idiom that's emerged that I've noticed.
> 
> For language precedent, it's pretty strong. Here's a few right off the top of my head:
> 
> \- Java: \`public boolean equals(Object other)\`
> \- C++: \`boolean operator==(T other)\`
> \- Rust: \`std::cmp::Eq\<T\>\`, used by its \`==\` operator
> \- Haskell: \[\`Data.Eq\`\](https://hackage.haskell.org/package/base-4.12.0.0/docs/Data-Eq.html)
> 
> For naming, I propose \`Symbol.equals\`. This goes along with the idiom most are already using. And for standard library containers:
> 
> \- Error objects: identical name and message and deep equal own expando properties. Stack should not be considered for the purposes of this.
> \- RegExp objects: identical pattern and equivalent flags (\`/gi\` and \`/ig\` are considered equivalent).
> \- Arrays: identical length and deep-equal entries, but ignore expando properties
> \- Maps: size is identical, each key of \`this\` is deep-equal with a key in \`other\` and their corresponding entries are also deep-equal
> - The idea is that these should be compared deeply in the same way objects are, just instead of string equality, it's deep object equality.
> - Algorithm note: \[I've tried to distill that into something sufficiently fast here\](https://github.com/isiahmeadows/clean-assert/blob/master/lib/match.js#L246-L312). Either you'll need to encode similar in the spec or leave it implementation-defined for reasonable performance.
> \- Sets: size is identical and every key in \`this\` is deep-equal with a key in \`other\`
> - The idea is that these should be compared deeply in the same way objects are, just instead of string equality, it's deep object equality.
> - Algorithm note: \[I've tried to distill that into something sufficiently fast here\](https://github.com/isiahmeadows/clean-assert/blob/master/lib/match.js#L314-L383). Either you'll need to encode similar in the spec or leave it implementation-defined for reasonable performance.
> \- Array buffers, shared array buffers, and array buffer views: equal byte data
> \- Promises: identical status and deep-equal value if settled, reference identity if pending
> 
> The default behavior should still of course be the standard algorithm, and it's left implied that types of course also need to be equal.
> 
> \-----
> 
> I could also see HTML wanting to hook into this as well:
> 
> \- Event: \`detail\` deep-equal, \`eventPhase\` and mutable properties ignored, all other properties identical
> \- Node: children deep-equal
> \- Element: attributes and children deep-equal
> \- CharacterData: data equal
> \- Range: equivalent contents
> \- Request: equivalent target/headers/etc.
> \- And so on

---

_[View the full topic](https://es.discourse.group/t/symbol-equal-a-way-to-define-the-weak-equals-operator-on-objects/2651)._
