-
Notifications
You must be signed in to change notification settings - Fork 75
Unary operator ??
#36
Comments
Oops, shame on me :/ |
A prefix won’t work, because you can’t handle the use case where |
|
That’d be very verbose in a longer chain that has intermixed optional and required lookups. I’m not sure how that’d be better than a multi character token? |
Oops, I think I misunderstood your comment. I have to admit that this may be confusing with the current |
@saschanaz If I understand your proposal correctly, it does the same thing as Optional chaining, except that you put a
has the same semantics as I prefer to put the Also:
Optional chaining could also be extended as: |
Exactly.
I think a challenge here is that we would introduce several new operators IMO Instead, here, |
Having several new operators is not an issue if the pattern is regular: as a precedent, consider the compound assignment operators:
Right; for that reason, we’re going to change |
(Assuming we actually want optional
If we use unary operator we can do |
For the extension I was thinking of, only the LHS of the operator would be checked whether it is nullish. If we wanted, we could morph A possible extension that does have use cases, is ”optionally iterable”, or ”nullish treated as a void iterator”; and it is not about binary operators, but syntactical constructs like |
The binary operator
?.
means optional chaining, but here the unary operator??
means it gets an "optional-chaining" state that the following syntactic access to the "optional" object doesn't throw even if the object is null/undefined.Further extension:
This way we won't get 3-character-combined(if there was a single character that could be safely used.)?.[
.What do you think? Too surprising syntax to use? Is this previously proposed? Possible syntactic problem? Too much spec change?
The text was updated successfully, but these errors were encountered: