operator overloading proposal

Michael Theriot michael.lee.theriot at gmail.com
Sun May 15 16:56:21 UTC 2016


What if you used a target parameter to indicate assignment?

```js
operator +(a, b, target = new obj()) {
  target.val = a.val + b.val;
  return target;
}

// or... no arrow functions...

operator +(other, target = new obj()) {
  target.val = this.val + other.val;
  return target;
}

// or... just a boolean

operator +(other, assign) {
  let target = assign ? this : new obj();
  target.val = this.val + other.val;
  return target;
}
```

And throw a TypeError if an assignment does not return the same object.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160515/051d775a/attachment.html>


More information about the es-discuss mailing list