Open dead-claudia opened 3 years ago
The stage 1 proposal is about investigating a problem space; it makes sense to me that we’d need a generic protocol to be able to solve this problem for all objects, not just built-ins.
@ljharb I'm aware. This can be revisited later if it's too premature.
I feel this is ripe for a symbol that allows extending and modifying the equality check. Library precedent is rather lacking (unless you consider Fantasy Land's Setoid spec 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:
public boolean equals(Object other)
boolean operator==(T other)
std::cmp::Eq<T>
, used by its==
operatorData.Eq
For naming, I propose
Symbol.equals
. This goes along with the idiom most are already using. And for standard library containers:/gi
and/ig
are considered equivalent).this
is deep-equal with a key inother
and their corresponding entries are also deep-equalthis
is deep-equal with a key inother
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:
detail
deep-equal,eventPhase
and mutable properties ignored, all other properties identical