Operators overriding

Sander Deryckere sanderd17 at gmail.com
Tue Dec 22 18:45:03 UTC 2015

IMO, operator overloading is important and different enough to warrant a
separate syntax.

But the difficulty isn't in defining the operator, but in the ambiguous
cases. Like what to do when there are 2 different types, how to make sure
certain relations will stay correct, ...

There's a nice presentation from Brendan Eich here:


2015-12-18 21:24 GMT+01:00 KOLANICH <kolan_n at mail.ru>:

> Hello. What do you think about overriding operators using proxies?
> For example
> function A(r=""){
> this.rep=r;
> return new Proxy(this,{operators:{"+":function(a,b){return new
> A(a.rep+"+"+b.rep);}}});
> }
> let a=new A("a"), b=new A("b");
> let c=a+b;
> console.log(c.rep);//a+b
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20151222/4a398795/attachment.html>

More information about the es-discuss mailing list