4 ms·
So my project for this week has been removing jQuery from my app. I have to say it's been surprisingly easy. The only thing that's been annoying is that jQuery
by Alex3917 5y ago
So my project for this week has been removing jQuery from my app. I have to say it's been surprisingly easy. The only thing that's been annoying is that jQuery ignores the difference between querySelector and querySelectorAll, and just treats any operation done on a jQuery selection as if it were mapping a function to each item in a list. Which makes it super easy to write, but makes it much more difficult to know what's actually happening, and mildly annoying to then re-write.
That said, in addition to forcing me to restore a lot of fun animations that I had previously broken while porting the site from AngularJS to Angular, it also just ended up making the code a lot better. A lot of the times when we were doing something with jQuery, the same thing could have been done more cleanly using [ngClass] or whatever. So taking the three or four days to remove jQuery actually made the business logic of the site much easier to understand. Performance benefits aside, I'd definitely recommend it for this reason alone.
- pupppet 5y agoThe way jQuery queries single or multiple elements was my favourite feature. Find xyz class and do something with it, I don’t care if there’s one instance or one thousand.
- Alex3917 5y agoYeah, the problem is just that later it makes it harder to go back and find code that's no longer working properly, dead code, and unused CSS. The fact that vanilla JS will throw an error when you try to perform an element operation on null is actually quite useful.
- claviska 5y ago> The only thing that's been annoying is that jQuery ignores the difference between querySelector and querySelectorAll, and just treats any operation done on a jQuery selection as if it were mapping a function to each item in a list. Which makes it super easy to write, but makes it much more difficult to know what's actually happening Does it though? Even years after moving on from jQuery it’s always very clear when reading old code that all selectors will be matched. There’s less cognitive load knowing you’re querying all matching items by default than mentally parsing the difference between querySelector and querySelectorAll, and also having to spread the result because NodeList doesn’t support array functions.