Existential Operator / Null Propagation Operator

Herby Vojčík herby at mailbox.sk
Tue Apr 7 18:58:56 UTC 2015



Christoph Pojer wrote:
> it doesn't have to be a bug. It asserts that if a is not
> null/undefined, it must have a property b. This can be enforced

Oh, that is completely different semantics. IMNSHO, it goes against DWIM.

> through static typing.
>
> On Tue, Apr 7, 2015 at 10:07 AM, Nick Krempel<ndkrempel at google.com>  wrote:
>>
>> On 7 April 2015 at 18:03, Nick Krempel<ndkrempel at google.com>  wrote:
>>> On 6 April 2015 at 20:01, Jordan Harband<ljharb at gmail.com>  wrote:
>>>> If I want the short circuit in option 1, I'd do `a?.b?.c` to indicate
>>>> that, whereas in option 2 if I don't want the short circuit, I'm forced to
>>>> use separate variables.
>>>
>>> Worth noting that an option 1 `a?.b?.c` differs from an option 2 `a?.b.c`
>>> in that the latter is effectively asserting that if a != null then its b
>>> property is also != null, whereas the former is more lenient in what it
>>> accepts.
>>>
>>> Also you are not forced to use separate variables in option 2, you can
>>> just use parentheses: `(a?.b).c` - hence the whole discussion of lack of
>>> transitivity (more correctly, associativity) for option 2. Or did I
>>> misunderstand what you're trying to achieve?
>>
>> ...but thinking about it further, wouldn't you always want the short circuit
>> semantics? i.e. an option 1 `a?.b.c` is almost certainly a bug?
>>
>>
>>
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>
>
>


More information about the es-discuss mailing list