How I imagined *binary* operator invocation would work is this:
Our example: a + b
If a or b is an object we try to look for an overloaded operator to
call like so:
(a[Symbol('+')] || b[Symbol('+')])(a, b)
^ disregard that I'm assuming both a and b are objects I can index safely
Okay, so turns out neither a nor b have an overloaded operator for
'+'. We default to calling the normal operator handler that coerces
with valueOf() as necessary.
To me this seemed rather simple.. Operators would just be defined
like: some_object[Symbol('~')] = function (lhs, rhs) { ... }
The only confusion I see is if we want to define explicitly the
postfix or prefix form of unary operators like ++. I don't know what
I'd call them as symbols.
I always saw overloading operators with Symbols, but you could just
have reserved member names on the prototype of the object as well ~
'++operator' similar to C++ ?
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss