Closed rbuckton closed 7 years ago
If I am following EvaluateCall correctly, it looks like (1) above is the correct interpretation according to 2.a.i. of the algorithm steps. It would be worth adding this example to https://github.com/tc39/proposal-optional-chaining#semantics.
Thanks. I still think it may be worth adding to the examples in README.md as its a common enough case.
@rbuckton
The README has already the following example: a?.b.c().d
. But yes, there should be more explanations.
You can check the README of my own repo for more detailed explanations (https://github.com/claudepache/es-optional-chaining), although the “official” feature may have some differences.
@rbuckton The updated README must answer your question. Please check and say if it is OK.
In C#,
o?.m()
returnsnull
ifo
isnull
and does not throw. Given that in this proposal we havef?.()
, which returnsundefined
iff
isundefined
, what is the expected behavior ofo?.m()
in this proposal?o?.m()
returnsundefined
ifo
isundefined
.o?.m()
throws ifo
isundefined
. To avoid the error, you must writeo?.m?.()
.If this proposal were to use the exact semantics of C#, then
f?.()
would not be legal, and you would instead need to writef?.call()
. I'm not saying we should use the semantics of C#, just that developers from other languages with experience with this feature may intuitively believe that (1) is the correct behavior.