What sucks about jQuery
I should start this post out by stating that I use jQuery daily with work and my personal projects and I mainly enjoy the benefits it provides me. I think the team do a great job and I’m very happy that they built and continue to maintain it. With that out of the way, let’s look at a few jQuery API pain points.
Overloading of methods
jQuery has a method called
load() that does two things: if is shorthand for
bind("load") and it also can make an XHR request and inject the response into an element. The other madness is the
toggle() function, where it can either toggle an element’s visibility, or sequentially step through a list of function arguments passed to it on click.
Methods arguments’ types invoke different behaviours
Back in the day, jQuery forums were littered with when I AJAX in the HTMLs, the events break, how I fix? type issues. Instead of learning about event delegation, many developers clambored aboard
live(), which appeared to work like magic (except the problem of performing a selector look up for no real reason at all). Soon after,
delegate() was introduced to address the shortcomings of
live()1, which was eventually deprecated in favour of
on(), which seem to read like the old
onclick type event listeners that plagued the early days of web development.
Convenience event convenience methods
jQuery has convenience methods, such as
click(), that maps to
trigger("click") without an argument or
on("click", fn) with an argument. Is this worth the extra methods living on
$.fn? Well, maybe2. It’s another case of a jQuery method doing too much for its own good.
Weird API names
Take a look at the
css() method. We all know CSS standards for Cascading Style Sheets, which is a method of defining styles for a website. So isn’t it a bit weird to call the API method css? Wouldn’t something like
style() suit it better?
I forgive you jQuery, I still love you
This post was just to get a few jQuery related annoyances off my chest. These sort of things are pretty much set in concrete now unless the jQuery team want to go the slow route of deprecating them for better alternatives.
Want to discuss this post? Just mention me @alexdickson.