es5 bug, operator == and valueOf
Peter van der Zee
ecma at qfox.nl
Wed Dec 1 00:45:20 PST 2010
Has an operator like >== ever been proposed? So the "strict" relational
operator that returns NaN if typeof left and right don't match.
If so, why was it shot down? Bloat? Relatively useless?
- peter
On Wed, Dec 1, 2010 at 1:45 AM, Brendan Eich <brendan at mozilla.com> wrote:
> On Nov 30, 2010, at 3:25 PM, Fyodorov Bga Alexander wrote:
>
> > @apipkin have found logic bug
> > `{valueOf: function(){ return 1 }} == {valueOf: function(){ return 1 }}`
> > // false
> > `{valueOf: function(){ return 1 }} >= {valueOf: function(){ return 1 }}`
> > // true, ok
>
> This is not a bug in ES5, although you could argue it's a design flaw in
> JS. Recall that
>
> typeof a == typeof b && a == b <=> a === b // implies, in both directions
>
> Two object initialisers never evaluate to the same object reference, and
> === compares references, and == here has same-typed (object) operands, so it
> is the same as ===.
>
> Relational operators do convert objects. You could argue this is a design
> flaw; or that this is a win but then == should convert objects as well --
> but if that is a flaw, it's only in hindsight, since === came after == and
> without === there would be no way to distinguish object references without
> implicit conversion.
>
> Really, implicit conversions (not the same as operator methods) are a
> design flaw in my view. They make == (ignoring NaN) not an equivalence
> relation.
>
> But again, not an ES5 bug. Did you read ES1-3 on == and valueOf
> differently?
>
> /be
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20101201/5e21da09/attachment.html>
More information about the es-discuss
mailing list