Optional Chaining (aka Existential Operator, Null Propagation)

John Lenz concavelenz at gmail.com
Thu Feb 4 19:03:47 UTC 2016


On Thu, Feb 4, 2016 at 10:06 AM, Claude Pache <claude.pache at gmail.com>
wrote:

>
> Le 4 févr. 2016 à 17:47, John Lenz <concavelenz at gmail.com> a écrit :
>
>
> [...]
>
>
> Waldemar's example makes the problem obvious but I think we could do use,
> which I think is preferable to the proposed:
>
> .?
> (?)
> [?]
>
>
> Yes, that syntax is possible. Whether it is preferable is a question of
> taste. Personally, I don’t like it:
>
> * I slightly prefer `?.` over `.?` for the following reason: The `?.`
> token may be conceptually separated in two, first the question mark which
> checks whether the expression at its left evaluates to null/undefined (and
> orders to stop processing if it is the case); then the dot which proceeds
> with property lookup.
>
>
* I find that the question mark inside the brackets is out of place, as it
> isn’t part of the arguments (for function call) or of the expression
> defining the key (for property access).
>

I agree with this but I think I would get used to ".?", etc.   "?.(" and
"?.[" are awkward, and longer (and harder to type).  ".?" "(?" and "[?"
would parse easily, are short


>
>
>
>> [...]
>
>
> yes, I meant the equivalent to:
>
> x ?: value
> x == null ? x : value
>
>
> I assume you meant: `x != null ? x : value`
>

haha, yes


>
>

> Note that this is a completely different operator. For the proposed
> optional chaining operator, we stop processing when the LHS is
> null/undefined; while for the `?:` null-coalescing operator, it is the
> other way round. Also, the precedence is not the same.
>
> I have wilfully restricted the scope of my proposal to optional chaining
> only, because of its intrinsic technical complexity.
>

sure.  that is very reasonable.


>
> —Claude
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160204/96297ac7/attachment.html>


More information about the es-discuss mailing list