tc39 / proposal-array-equality

Determining Array Equality
MIT License
70 stars 4 forks source link

Add a symbol to allow extending and modifying the equality check #6

Open dead-claudia opened 3 years ago

dead-claudia commented 3 years ago

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:

For naming, I propose Symbol.equals. This goes along with the idiom most are already using. And for standard library containers:

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:

ljharb commented 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.

dead-claudia commented 3 years ago

@ljharb I'm aware. This can be revisited later if it's too premature.