How should operator overloading work?

Coroutines coroutines at gmail.com
Wed Dec 30 19:07:26 UTC 2015


On Wed, Dec 30, 2015 at 8:31 AM, Nicolas B. Pierron
<nicolas.b.pierron at mozilla.com> wrote:
> 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['_>>=_'].

The "C++ way" of naming these would probably be nicer, but maybe
something like this:

obj[Symbol['operator+']] = (lhs, rhs) => ...
obj[Symbol['++operator'] = (rhs) => ...
obj[Symbol['operator>>='] = (lhs, rhs) => ...

I saw that you wanted to say where the operator appears (if it's
binary, unary, postfix, or prefix) depending on the _ - but certain
operators (like >>=) can only be binary operators so there wouldn't be
any confusion unless we want to get into the land of defining custom
operators like in Ruby. :-)


More information about the es-discuss mailing list