It seems like this model can be abused in the same way that having separate
methods for assign operators can be abused.  I think having separate
operators and automatically using `[[plusOp]]` if `[[assignPlusOp]]`
doesn't exist is an easier programming model.  People who need the extra
performance can go the extra mile and define both operators.

On Sun, May 15, 2016 at 9:56 AM, Michael Theriot <
michael.lee.ther...@gmail.com> wrote:

> 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.
>
> _______________________________________________
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to