Existential operator (was: ||= is much needed?)
vitteaymeric at gmail.com
Mon Jun 18 04:13:51 PDT 2012
This is related to what I was trying to figure out in the "more fun with
undefined" thread, maybe it is wrong or have too many impact but I was
about to suggest :
8.9.1 GetValue (V)
5. If IsUnresolvableReference(V), return undefined
11.2.1 Property Accessors
Runtime Semantics: Evaluation
3. If baseValue is an abrupt completion or undefined, return baseValue.
Why not, instead of adding "?" operator ?
Le 18/06/2012 07:11, Brendan Eich a écrit :
> Sorry, meant to start a new thread for:
> As the Syntax section hints, we can't also adopt CoffeeScript's ?(
> variant, which enables foo.bar?(args, go, here).baz and the like. The
> C syntax heritage prevails.
> Brendan Eich wrote:
>> David Herman wrote:
>>> On Jun 15, 2012, at 5:57 PM, satyr wrote:
>>>> On Sat, Jun 16, 2012 at 4:33 AM, David Herman <dherman at mozilla.com
>>>> <mailto:dherman at mozilla.com>> wrote:
>>>> As for null, I can see how there's confusion about whether to use
>>>> null vs undefined, and so I can see why CoffeeScript would just
>>>> try to blur the distinction between them.
>>>> Not just for blurring. Rejecting `null` is essential for
>>>> CoffeeScript's "existence" due to `?.`, the soak/safe access operator.
>>> I think you could make a case for ?. defaulting for both but ??
>>> defaulting only undefined. The case goes something like this:
>>> - The purpose of ?? is to provide a default value when no value was
>>> - The purpose of ?. is to fail soft when doing a property lookup.
>>> Both null and undefined throw when doing a property lookup.
>> Agreed. This is one choice, it's plausible because of the distinction
>> between defaulting (which requires intentional passing of a "please
>> default" sentinel value, or not passing a trailing actual argument)
>> and soaking up null-or-undefined.
>> Yes, we could make ?? and ??= do the same for null as for undefined.
>> I'm not sure that's the right choice, but it's a choice. For
>> foo.bar?.baz, though, the clearer choice is to avoid throwing, which
>> means evaluating to undefined if foo.bar is missing (evaluates to
>> undefined) *or* has a value not coercible to object type (null or
>> undefined). See
>> es-discuss mailing list
>> es-discuss at mozilla.org
> es-discuss mailing list
> es-discuss at mozilla.org
Email : avitte at jcore.fr
Web : www.jcore.fr
Webble : www.webble.it
Extract Widget Mobile : www.extractwidget.com
BlimpMe! : www.blimpme.com
More information about the es-discuss