Existential Operator / Null Propagation Operator
rubys at intertwingly.net
Tue Jun 2 18:25:32 UTC 2015
On Tue, Jun 2, 2015 at 1:31 PM, Sander Deryckere <sanderd17 at gmail.com> wrote:
> 2015-06-02 18:57 GMT+02:00 Brendan Eich <brendan at mozilla.org>:
>> You might hope for that, but as we both noted, `?[` is not going to fly.
>> Don't break the (minified) Web.
> Which is why my proposal was about `??`. I believe there's currently no
> valid way to use a double question mark in JS, so even `??[` should be easy
> to figure out what it means.
>> The prefix idea generalizes:
>> and if you are not using computed property names, rather literal ones:
> I found this syntax to conflict with itself. As Andreas Rossberg says, what
> does `orders[?client.key].price` mean? Does it mean "check if the client
> exists, and if not, return the price of the null order", or does it mean
> "check if the order for this client exists, and return null if it doesn't"?
> I don't see a way how both meanings can be made possible with this form of
> prefix notation.
Um, if I'm reading Brenden correctly, neither?
"check if the client exists, and if not, return the price of the null order"
"check if the order for this client exists, and return null if it doesn't"
I would suggest a third interpretation for `orders[?client.key].price`:
===> (orders ? orders[client.key] : null).price
I think that the problem here isn't that it is ambiguous, it is that
it isn't obvious. Something that might be more obvious but requires
an additional character: `orders.?[client.key].price`.
More precisely, the suggestion is to standardize on .? and allow it to
be followed by either a simple name, a square bracket, or a left
> es-discuss mailing list
> es-discuss at mozilla.org
- Sam Ruby
More information about the es-discuss