-
Notifications
You must be signed in to change notification settings - Fork 75
Clarify behavior of 'o?.m()' #16
Comments
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. |
See #2. |
Thanks. I still think it may be worth adding to the examples in README.md as its a common enough case. |
@rbuckton 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.The text was updated successfully, but these errors were encountered: