Re: Ternary operator enhancement proposal

2019-11-13 Thread Claude Pache


> Le 13 nov. 2019 à 03:43, devlato  a écrit :
> 
> Hey folks,
> 
> not sure if you haven't discussed something similar, but what do you think 
> about making an enhancement for the ternary operator, to make it more 
> powerful? 
> I've created a small explanatory doc on GitHub: 
> https://github.com/devlato/proposal-ternary-placeholder
> 
> Warmest regards,
> Denis
> 

The generic problem is: you do some computation, and you want to reuse the 
result of that computation later.

The generic solution is to use a temporary variable:

```js
// declare a temporary variable at the top of some scope
var _;

// later, use it:
const X = () => (_ = x?.y?.z) ? doSomethingWithValue(_) : null;
```

Now, you are not satisfied with the existing solution, and you want to avoid 
declaration of temporary variables in some outer scope...? Maybe:

```js
const X = () => (#1 = x?.y?.z) ? doSomethingWithValue(#1) : null;
```

(Any similarity with 
https://developer.mozilla.org/en-US/docs/Archive/Web/Sharp_variables_in_JavaScript
 

 is not at all fortuitous.) However, I’m not convinced that the need to declare 
your temporary variables is such a problem that it is worth the introduction of 
new syntax.


—Claude___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Ternary operator enhancement proposal

2019-11-13 Thread Michael Luder-Rosefield
I put forward a similar proposal a while back:
https://esdiscuss.org/topic/proposal-result-forwarding-ternary-operator
--
Dammit babies, you've got to be kind.


On Wed, 13 Nov 2019 at 02:46, Jacob Pratt  wrote:

> Aside from the fact that using a non-reserved identifier would break
> back-compatibility, I'm fairly certain pattern matching would allow for not
> recalculating the value while also being far more readable.
>
> On Tue, Nov 12, 2019, 21:43 devlato  wrote:
>
>> Hey folks,
>>
>> not sure if you haven't discussed something similar, but what do you
>> think about making an enhancement for the ternary operator, to make it more
>> powerful?
>> I've created a small explanatory doc on GitHub:
>> https://github.com/devlato/proposal-ternary-placeholder
>>
>> Warmest regards,
>> Denis
>>
>> ___
>> 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
>
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss