What I've long wanted is an assignment operator which evaluates to the
pre-assignment value of the LHS.
You know, sort of like `a++` evaluates to the pre-incremented value of `a`.
We could call this this "post-assignment" operator.
Has anyone ever proposed that?

```
let a = 1;
console.log(a =^= 2); // logs 1 and then sets a to 2
```

On Mon, Apr 13, 2020 at 9:32 AM Jordan Harband <[email protected]> wrote:

> Are you familiar with https://github.com/tc39/proposal-logical-assignment/
> ?
>
> On Mon, Apr 13, 2020 at 2:17 AM Sultan <[email protected]> wrote:
>
>> The following would assign to the address foo in obj if and only if it
>> has not already been assigned.
>>
>> var obj = {}
>> var foo = Math.random()
>> obj[foo] ?= 1
>>
>> The same can be said for:
>>
>> var undef
>> undef ?= 1
>>
>> Which could both be transpired to
>>
>> type obj[foo] === 'undefined' && obj[foo] = 1
>>
>> or
>>
>> type a === 'undefined' && undef = 1
>>
>> respectively.
>> _______________________________________________
>> es-discuss mailing list
>> [email protected]
>> https://mail.mozilla.org/listinfo/es-discuss
>>
> _______________________________________________
> es-discuss mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/es-discuss
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to