A portion of some test jQuery code I dug up for this entry.
I was messing around with jQuery this weekend – we are interested in jQuery at work, but don’t currently support it.
I’ve been working – just on and off – with jQuery for a couple of years, and I have some strong opinions about the – what should we call it? – the JavaScript framework.
The first, and most important, is that I think it is going to be the defacto JS framework (if not already), which is one of the reasons I decided to dive into it. Powerful, and a lot of future potential.
That said, here are – to me – the current strengths and weaknesses of the framework:
The Good
- It makes some complex JS tasks pretty simple. For example, the hide/show of a DIV is a basic JS device. Pretty easy in JS, but with jQuery, one can do the same but with animations (face, slide up/down). Sexy and simple.
- For the most part, the promise of jQuery has been like the (sorta false) promise of the compiled language Java: Write once, run anywhere. For the most part, jQuery code behaves the same on virtually all platforms/browsers. Sure, there are bugs, but as anyone who has had to run JS (or HTML) against a wide variety of devices, all I can say is jQuery is a time-saver. You still (should always) test, but fewer cross-platform/browser issues pop up. This is, of course, a veddy good thing.
The Bad
- jQuery is a wrapper around JS, and the wrapper makes for ugly code, hard to follow. Mix jQuery with regular JS, and it’s just a mess in many cases.
- Debugging jQuery is tough: Even if the full (max vs. min) version of jQuery is installed, debugging is very difficult due to the wrapper notion of jQuery. This’ll improve in the future, but right now, no tools really work as well on jQeury as they do on non-wrappered JS.
- Like many plug-in environments, jQuery makes the hard simple. Which is awesome. Until someone requests the slightest change. Then, the non-JS developer will be lost.
- In many languages, the dollar sign ($) marks a variable – i.e $firstname=”John” In JS, there are no dollar-sign variables – var firstname=”John”. OK, not a biggie, but — jQuery introduces the dollar sign as an object variable marker. Confusing. Let’s say there’s a DIV with an ID of “fadeMe” and we want to hide it as an onClick event:
$(“#fadeMe”).click(function() {
$(“#fadeMe”).slideUp(4000);
}) // end fadeMe click eventThis’ll hide the fadeMe DIV (fade away) after four seconds, but a weird soup mix of $(# and so on. And get a parens or bracket or sqiggly bracket (braces) wrong: well, it all bombs. Make Perl punctuation soup look sane. (NOTE: But still powerful – will animate (slide up) this DIV over the course of X seconds with minimal code.)
The Unknown
- The JS wrapper is rapidly changing, which is good – it’s addressing shortcomings and adding functionality – but it’s also problematic for legacy code. Function x() needs to be changed to xy() or won’t return expected result and so on. This is true of all languages/frameworks, but jQuery is moving at an exceptional clip.
- JS has been around for almost 20 years (launched as LiveScript), but it’s only caught on in the last 10 years (DHTML) and really gotten hot in the last five or so years (AJAX!). jQuery has, as of late, helped fuel this acceleration. What’s next?
- Mobile is all the rage these days, and I’d be stunned if there isn’t some sorta jQuery mobile movement out there. I’m not a mobile developer, but I’ve heard/read nothing about same – but I’m sure something’s there.