How should operator overloading work?

Nicolas B. Pierron nicolas.b.pierron at
Wed Dec 30 16:31:52 UTC 2015

Note, do we want to distinguish the binary operator Symbol['_+_'] from
the unary operator Symbol['+_'].
Also, I am not sure how extendable the language is, especially if we
are looking for operators like  Symbol['_>>=_'].

On Tue, Dec 29, 2015 at 4:41 PM, Coroutines <coroutines at> wrote:
> 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
> es-discuss at

Nicolas B. Pierron

More information about the es-discuss mailing list