r/javascript • • Feb 06 '17

You Truly Don’t Need jQuery

https://medium.com/@doug.miller/you-truly-dont-need-jquery-5f2132b32dd1
0 Upvotes

3 comments sorted by

28

u/dmtipson Feb 06 '17 edited Feb 06 '17

I don't advocate using jQuery myself unless for a specific need, but most of these articles are weakly argued, and this one is no exception.

The point of jQuery's DOM api is not just element selection, but standard methods for logical traversal and manipulation (can you off the top of your head write an operation that lists all the grandchildren of a given node? Did you know said operation would need Monadic flattening? Do you even know what that is?). While all us React-heads might never actually need those things anymore, they're still extremely useful and well thought out for what they do if you happen to... and if that's your need, then I doubt many devs are even familiar enough with array operations to properly navigate a DOM tree and do all the traversal and add/removal opertions with vanilla js alone.

Oh wait, did I say Array methods? Whoops, sorry no: DOM node lists aren't real arrays and don't have array methods: they'd have to be converted post selection. But people testing selector speed never seem to take that into account when comparing this (i.e. they don't include the cost of running Array.from on the result of the native DOM selector methods, despite that requiring an entire extra iteration over the entire list under the hood!) jQuery abstracts all those sorts of annoyances away in a clean, chainable api.

While it's original brilliance was basically normalizing hundreds of browser version bugs, and that's less and less of an issue today, it's still basically a solid utility belt for the things it does. Which, yes... may not be things you need. But the same can be said for, say, lodash (and hey: believe me, nothing drives me crazier than importing a react module only to find out that it includes an ENTIRE copy of lodash just to import a single function like uniqueID that's literally 2 lines of code to write yourself). You might not need lodash if... but the point is, you do need it if you happen to want to just pull out some battle-tested utility methods and use them without having to muddle through writing them yourself, remember all the possible gotchas, remember what the fastest implementation might be, then and write tests.

So I mean, yeah, the gist of these articles is usually right: don't lib out when you just need a few choice operations you can and should learn. But so many of the details of these criticisms just totally miss the point of why you'd use a library in the first place: the sorts of problems you'd be trying to solve.

As for ajax well... Promises yeah? I guess a hypocrite like me could write a whole article called "you might not need Promises if..." so...

3

u/mwcz Feb 06 '17

Well said.

2

u/[deleted] Feb 06 '17

I suppose the author was so blinded by their hate of jQuery, they forgot to consider the value proposition of the examples they're presenting, where the "vanilla" versions are consistently far more verbose and less powerful than the jQuery alternatives.

If anything, this blog post is a proof that jQuery still has long legs, even though browsers don't have nearly as many bugs and inconsistencies as before.