Optional Chaining (aka Existential Operator, Null Propagation)

Alexander Mekhonoshin invntrm at yandex-team.ru
Thu Aug 25 14:05:08 UTC 2016


// Excuse my beginner’ English

I have a few (3) thoughts:


1. binary ?.
If a === null: a?.b.c === undefined

If a?.b === null: a?.b.c // throws exception

If a?.b === null: a?.b?.c === undefined

If a === 0: a?.b.c === undefined

If a === '': a?.b.c === undefined

If a in not defined: a?.b.c // throws exception

If a === undefined but defined: a?.b.c === undefined



2. unary ?.

window?.navigator?.toString()

browser: "[object Navigator]"
node: ReferenceError: window is not defined

here i suggest syntax for exception-slient accesing globals:

?.a === hostGlobalObject?.a
?.a?.b === hostGlobalObject?.a?.b


3. groupped ?.()
Syntax for the full existential chain case:

.?(a.b.c) // equals with typeof a !== 'undefined' && a.b && a.b.c

I use .? here too because ?:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160825/93d1e6bd/attachment.html>


More information about the es-discuss mailing list