Object.eq is ready for discussion

Maciej Stachowiak mjs at apple.com
Sun Sep 5 08:28:50 PDT 2010

On Sep 5, 2010, at 7:40 AM, Mark S. Miller wrote:

> http://wiki.ecmascript.org/doku.php?id=strawman:egal
> I have previously taken the position on this list that we should not add a third equality construct to JavaScript. However, it is relevant to several other strawmen that are likely to advance -- hasCode, Maps and Sets. Also, its absence repeatedly bites me. I often accidentally code === when I mean Object.eq because it's so hard to remember when ==='s brokenness matters. Nevertheless, I am still ambivalent about adding it as standard equipment. Opinions?

I think it's nearly mandatory, as the equivalence relation paired with Object.hashcode. A hash function is only meaningful in the context of an equivalence relation.

Other possibilities:

- Make Object.hashcode pair with === or == instead of Object.eq: formally impossible, because neither is actually an equivalence relation. Less formally, possible at the cost of making it impossible to use NaN as a hash key, or distinguish 0 from -0 as hash keys.

- Make Object.hashcode correspond to an equivalence relation that is described but not provided as a predefined function - now actually using hashcode becomes needlessly complicated and error prone.

It might even be desirable to name Object.hashcode something that makes the relationship to eq clear - Object.eqHash? On the other hand, it seems somewhat unlikely that other hash/equivalence pairs will be introduced to the standard, so maybe it doesn't matter.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20100905/fee80e33/attachment-0001.html>

More information about the es-discuss mailing list