r/node • • Nov 10 '20

Conditionally call a function with optional chaining.

Post image
345 Upvotes

126 comments sorted by

View all comments

Show parent comments

-20

u/OmgImAlexis Nov 10 '20

This is a worse way of doing it.

11

u/threeys Nov 10 '20

Why is it worse?

-6

u/OmgImAlexis Nov 10 '20 edited Nov 10 '20

It’s harder to read the intent and doesn’t add anything helpful for the few chars it saves.

4

u/burnblue Nov 10 '20

Is it still a few characters when the function is deep?.inside?.an?.object?.()

2

u/ikeif Nov 10 '20

This is when I pulled it into a project.

Large JSON objects, so it was either constantly making shorthand assignments or being able to concisely do it this way.

People get so hung up on an option in a toolset. It’s not for every project, but some projects, it’s a good tool.