Swift style syntax
Isiah Meadows
isiahmeadows at gmail.com
Fri Oct 16 04:11:05 UTC 2015
Problem: that is currently a runtime ReferenceError, and it looks
ugly. And operator overloading has already been floated around in the
value types proposal. Having it available for everything isn't that
great of an idea, but for at least value types, it's not a bad one.
And the syntax/semantics here (in your email) is not very good. Also,
what about classes?
```js
class Pair {
constructor(x, y) {
this.x = x;
this.y = y;
}
operator(+)(other) {
return new Pair(this.x + other.x, this.y + other.y)
}
// etc.
}
```
I don't like that arbitrary behavior. It's non-obvious. -1 from me.
On Thu, Oct 15, 2015 at 9:40 PM, Yongxu Ren <renyongxu at gmail.com> wrote:
> I vote for operator overloading!
>
> I think this is probably going to be a good way to do it:
> ```
> //in local scope
> let operator(**) = (lhs,rhs) => Math.pow(lhs,rhs);
>
> //class method
> Complex.prototype.operator(+) = function(lhs,rhs){
> return new Complex(lhs.r+rhs.r,lhs.i+rhs.i);
> }
>
> //global, may not be an good idea
> operator(+) = (lhs,rhs) => lhs*rhs;
> ```
> //this will work for case above
> names.sort(>)
> ```
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
--
Isiah Meadows
More information about the es-discuss
mailing list