On Tue, Jun 2, 2015 at 1:31 PM, Sander Deryckere <[email protected]> wrote: > > > 2015-06-02 18:57 GMT+02:00 Brendan Eich <[email protected]>: >> >> 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: >> >> ?obj[key] >> obj[?key] >> obj[key1][?key2] >> >> and if you are not using computed property names, rather literal ones: >> >> obj.?prop1 >> etc. > > 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" ===> orders[client.?key].price "check if the order for this client exists, and return null if it doesn't" ===> orders[client.key].?price 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 paren. > _______________________________________________ > es-discuss mailing list > [email protected] > https://mail.mozilla.org/listinfo/es-discuss - Sam Ruby _______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

