Re:Show HN: A JavaScript function that looks and behaves lik...
by keb_ on Wednesday September 27, 2023 @09:05AM
(#37674085)
The strength of the pipeline operators comes when you have to do method chaining things like:
I already forgot the amount of parentheses I needed to close with while typing that.
[ Parent
| on HN ]
Re:Show HN: A JavaScript function that looks and behaves lik...
by williamcotton on Wednesday September 27, 2023 @09:28AM
(#37674368)
value.indent()
.exclaim()
.reverse()
.underline()
.capitalize()
There’s always the OOP version of method chaining!
Re:Show HN: A JavaScript function that looks and behaves lik...
by jonahx on Wednesday September 27, 2023 @10:08AM
(#37674879)
This won't look as good when you include all the boilerplate which defines those methods, and which needs to be repeated or otherwise included for every "value" type. You don't have to worry about this when they are pure utility functions.
Re:Show HN: A JavaScript function that looks and behaves lik...
by mhink on Wednesday September 27, 2023 @02:23PM
(#37678960)
Which is great until Prettier, in its infinite wisdom, decides it's better to stick four of these function invocations on one line and two on the next, so you have an obnoxious mishmash of tokens!
Re:Show HN: A JavaScript function that looks and behaves lik...
by pzmarzly on Wednesday September 27, 2023 @02:57PM
(#37679518)
Which is a problem of Prettier. I wish for the day that someone builds rustfmt but for Typescript, I will happily leave Prettier and StandardJS behind.
I think it could be done today with a (big) number of ESLint plugins.
Re:Show HN: A JavaScript function that looks and behaves lik...
by rat9988 on Wednesday September 27, 2023 @09:15AM
(#37674213)
No worries your ide will help you for the parentheses.
Re:Show HN: A JavaScript function that looks and behaves lik...
by keb_ on Wednesday September 27, 2023 @10:32AM
(#37675216)
IDEs and linters should not be a crutch methinks because not everyone uses the same IDE or text editor. Either way, it will still be awkward to read.
Better that you either avoid that pattern or at least indent it in such a way that its not so visually confusing. Or yknow use a pipe operator.