Operator overloading for non-value objects

Domenic Denicola domenic at domenicdenicola.com
Tue Jan 14 20:01:49 PST 2014


I was thinking of

function thirdPartyLib(val) {
  return val == "0";
}

thirdPartyLib(myLong); // exception
thirdPartyLib(Number(myLong)); // works

> On Jan 14, 2014, at 22:50, "Brendan Eich" <brendan at mozilla.com> wrote:
> 
> Domenic Denicola wrote:
>> Heh, yes, damned if you do, etc. etc. I was trying to think up a practical example where this would cause problems (e.g. in CSS libraries strings and numbers often mix), but all my cases involved an `==`-using third party library, in which case you'd just pass it `Number(myLong)` instead of `myLong` directly and move on with your life.
> 
> Wait, number works:
> 
> js> 0L == 0
> true
> js> 0L + 1
> 1L
> 
> Are you thinking of string?
> 
> /be


More information about the es-discuss mailing list