Open andyearnshaw opened 1 week ago
Yes, the proposal will be updated to include it. Especially I plan to change the syntax from ::
to dot-based syntax, so it's very natural to still use ?.
symbol, eg. document.querySelector("#myElement")?.do:let(it => { ... })
.
Note, one consequence of including optional chaining is we must simplify the hooks semantic. In the initial proposal, we have invoke
hook which can skip the method resolving step (this help some use cases like eventual send proposal), but ?.
semantic is based on that. Consider eventual send proposal itself also changed in past years and seems can't fully covered by extension proposal, I'd like to drop invoke
hook and keep extension methods using similar semantic with normal methods and private methods.
fwiw, obj?.do:
seems like it'd conflict with condition ? obj?.do : …
, parsing-wise.
Yeah, the separator also need to be reinvestigated.
Options:
obj.ext@method()
obj?.ext@method()
obj.ext#method()
obj?.ext#method()
obj.ext~method()
obj?.ext~method()
obj.ext!method()
obj?.ext!method()
obj.ext'method()
obj?.ext'method()
obj.ext::method()
obj?.ext::method()
It would be great if optional chaining was baked into the proposal:
Equivalent to: