r/javascript • • Mar 02 '19

Useful javascript one-liners.

https://medium.com/@smellycode/js-one-liners-8bc0a6af2345?source=friends_link&sk=a9295a05aef9e514e137fca7eeb89cd1
344 Upvotes

96 comments sorted by

View all comments

-5

u/BinxyPrime Mar 02 '19

You can do almost all of these in one line with lodash and its probably optimized better

11

u/Shaper_pmp Mar 02 '19

... at the cost of an additional external dependency for your project.

3

u/MakiBM Mar 02 '19

Which might be in your favor at this example. Things that are used often are better when standarized. It's cool wyen you hire a dev and he knows your tooling. You will end up having less code because there are bits to import and reuse rather than writing it from scratch. And you will have that exposed as a package for your project which barely happens when you drop one liner here and there as you go. Using tools like that helps in project maintaince, onboarding etc...

Dependencies are as good as your review process. You could stick to vanilla and let go react / vue / you name it - even if your custom solution would beat popular frameworks (but lets be realistic, this doesnt happen that often) you would end up creating big overhead for new members and need to wait for months for productivity to come... Its all about common language and making development comfortable.

4

u/Shaper_pmp Mar 02 '19

Things that are used often are better when standarized. It's cool wyen you hire a dev and he knows your tooling. You will end up having less code because there are bits to import and reuse rather than writing it from scratch.

Absolutely true, though you won't get much more standard, accessible and "less code" than using standard language features. ;-p

More seriously though, I'm not arguing against using dependencies. I'm arguing adding dependencies is not a cost-free action, so "lol just use Lodash" is advice that is only contextually useful in some situations - in others it could be a terrible idea.

2

u/MakiBM Mar 02 '19

We're on the same train :)