Skip to content
This repository has been archived by the owner on Jan 25, 2022. It is now read-only.

Can we simplify this to a single ?? #82

Closed
wintercounter opened this issue Mar 8, 2019 · 3 comments
Closed

Can we simplify this to a single ?? #82

wintercounter opened this issue Mar 8, 2019 · 3 comments
Labels
alternative syntax and semantics past ideas about alternative syntaxes that also change the semantics

Comments

@wintercounter
Copy link

Why it cannot be simply ?foo.bar.baz? I'm thinking about this since a few weeks now yet couldn't find anything against.

If an item in the chain is undefined, then instead of throwing an exception, it'll return undefined. Done.

@RayPS
Copy link

RayPS commented Mar 8, 2019

Interesting. I prefer place it at the end of a chain to fallback exception to undefined.

let username = foo.bar.baz.users[0].name? || 'Anonymous'

@wintercounter
Copy link
Author

wintercounter commented Mar 8, 2019

I'm not sure about the correct mechanics. Can the chain be "flagged" by the parser that you won't need exception during evaluation?
Also that syntax is already reserved for if shorthand.

@claudepache
Copy link
Collaborator

@wintercounter By design, you have indeed to write foo?.bar?.baz, i.e. put the question mark precisely at each place where you expect to possibly get null/undefined. We don’t think that reducing the number of question marks is worth the lost of precision.

That was already discussed in #29; see in particular #29 (comment) and #29 (comment), and the FAQ entry on the README that begins with ”In a deeply nested chain ...”

@claudepache claudepache added the alternative syntax and semantics past ideas about alternative syntaxes that also change the semantics label Jun 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
alternative syntax and semantics past ideas about alternative syntaxes that also change the semantics
Projects
None yet
Development

No branches or pull requests

3 participants