How should operator overloading work?

Andrea Giammarchi andrea.giammarchi at
Tue Dec 29 19:15:33 UTC 2015

I should probably read other threads too about this, but is `Symbol('+')` a
typo and it should be a property like any other well known `Symbol` so that
it's actually `Symbol['+']`, `Symbol['~']`, and others? AFAIK invoking
Symbol passing a string should create a named Symbol, and not a special one.

Thanks for any sort of clarification.
Best Regards

On Tue, Dec 29, 2015 at 5: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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list