Operator overloading for non-value objects

Brendan Eich brendan at mozilla.com
Tue Jan 14 14:44:55 PST 2014


Kevin Smith wrote:
> I'll stop there, because I don't know the details of the proposal.

Allowing value objects (and perhaps mutable object) to define operators 
means giving up some invariants, similar to proxies which can have 
incoherent has/get etc.

So I'm not sure what you are waiting for. A badly written user-defined 
value object? Those may be easy to cough up in order to complain about 
extensibility, but the whole point of value objects is to avoid hardcoding.

If you want an int64 spec/impl to evaluate, that'll take a bit longer. 
Preview:

js> 0L == 0
true
js> 0L === 0
false
js> typeof 0L
"int64"
js> 0UL == 0
true
js> 0UL === 0
false
js> 0UL == 0L
true
js> 0UL === 0L
false
js> typeof 0UL
"uint64"

Someone who insists on using === only can convert from one numeric type 
to another:

js> int64(0) === 0L
true

Of course you have to beware of values that convert lossily, but for 0, 
1, ... N, we have == and I think it ought to work.

/be


More information about the es-discuss mailing list