简体   繁体   中英

What are jQuery's limitations?

Joel always said to be careful when using 3rd party libraries. From my initial impressions, jQuery is great. What should I beware of when using it? What are the limitations? What headaches will I run into later on as I use it more?

I've used it extensively and I have to admit, I'm yet to run into any serious brick walls! I have come up against a couple of bugs which I had to find a quick fix for myself, and then do extra testing with the next jQuery release to ensure that the bug had been dealt with properly, but that's something which applies to any 3rd party library rather than just jQuery.

I think it's a fantastic library I must say, and whilst the advice concerning 3rd party libraries has merit, with the amount of Javascript usage having rocketed in this Web 2.0 world, and with so many little discrepancies between browsers, having a well-maintained library can really speed up development as it saves you the overhead of having to do all the legwork yourself.

I guess if I was to issue one warning, it would be to make sure you don't go overboard with it - whilst it really accelerates Javascript development by abstracting away loads of logic you don't need to worry about, there's always the risk you'll start writing an inefficient application because you don't realise exactly what demands you're placing on the browser. I would therefore advise you do plenty of profiling with the likes of Firebug to check what's going on under the hood.

@ mjc

$("a tip")
.you()
.can()
.chain()
.stuff()
.like()
.this();

And/or define a variable, for which to use the jQuery functions on:

var $tip = $("a tip");
$tip.choo();
$tip.choo();
$tip.train();

One thing I've run into with jQuery is that you end up chaining a lot of items together, and it tends to quickly get unreadable if you are not careful.

an example I can think of that illustrates this is on John David Anderson's blog :

There's a guy who wrote a logging function so you can figure out whereYou(are).whenYoureCoding().inThe(middleOf).a(jQuery).trainWreck().

I can see the power of chaining things together, but my guess is you've probably gone too far if you're needing to log things to the console mid-swing. There's probably little to no chance you're going to be able to read it a week from now, too.

jQuery is great - it can do whatever javascript can do, but quicker, and in less code. Its only limitations are the ones inherent in javascript as a client-side scripting language. Like any tool, it's possible to missuse, but unless your scripting needs are profoundly basic there's almost no reason NOT to use it.

I came across the following in my blog reading. It's not really limitations in jQuery but common mistakes made when using ASP.NET developers using jQuery:

http://encosia.com/2008/06/05/3-mistakes-to-avoid-when-using-jquery-with-aspnet-ajax/

@ BrilliantWinter

jQuery is not at all bloated. It's one of the smallest libraries out there.

All it's functions are extends of the jQuery object, which means you can detach whatever functionality you don't use, and make the footprint of the library even smaller than it's default size (15kb, Minified and Gzipped).

jQuery - and every other library for that matter - provides an API which is the same across all A-grade browsers. This abstraction leaves your code cleaner and less error-prone.

Finally, jQuery is used by major "players". Companies like Google, Dell, Digg and NBC use the library. This is not only a big seal-of-approval, but also an assurance that the developers of jQuery are very careful when revising the library, making sure nothing breaks and no bugs are introduced.

@BrilliantWater - Most people don't use jQuery to "learn", they use it because it's quicker and easier to use and causes less headaches than creating all the methods yourself. And the whole "bloated" argument is totally moot; jQuery is one of the smallest libraries out there and with more and more people getting broadband it's becoming less and less of an issue.

Plus, since jQuery is hosted by GoogleCode it's likely that it'll already be in the users cache since so many websites use it!

jQuery is awesome! I keep saying to myself that I need to learn another library but I really don't. jQuery has everything I need. I know it's not suited to all projects but it certainly has a place in most!

I've found jQuery to be indispensable when writing just about any useful bit of javascript. That said, one site I was working on wanted to do animations. I suggested NOT using flash, but performing the relatively "simple" animations that jQuery packages so well with jQuery. We used fades and slides and the like. In the end, it was too much for the browsers to handle (specifically IE, but FF showed signs of stress), and we had to scale almost all of it back.

jQuery is tons of fun to code with, and experiment with. It has a fantastic developer community that fields questions very quickly. Just be careful not to get too carried away! :)

The only downside to jQuery is its too simple and easy to use. You get a very low bar of newbies using it and doing some very strange and close to retarded things. Other than that, jQuery is beautiful and well crafted by a genius and his minions of smart programmers ensuring cross browser quality that reduces tons of work for the developer. Can't go wrong. If you don't like jQuery, you are a little bit off and probably don't bathe often enough.

UPDATE

This was a very old answer of mine. jQuery is really no longer necessary if you use querySelector and MDN reference as browsers have converged to be the same for the most part, unless of course you are still living in IE8 death land requirements. jQuery also lives globally which is bad if you are building modern JavaScript. jQuery is not really useful at this point aside from having some old school plugins not using modular syntax libraries.

Start to look toward modularizing JavaScript as that was the trend after jQuery. Pay attention to es6/es2015. Start using React/React Native OR Angular 2 for making apps as that's on par since it caught up to some degree.

Sorry, John Resig. At this point, people are like "John who?" even though he's still a genius in my book. I hope he gets off his laurels though and makes something even better.

Funny how things change.

You can always consider different frameworks if jQuery doesn't suit. Here's an example of mootools .

MooTools is a compact, modular, Object-Oriented JavaScript framework designed for the intermediate to advanced JavaScript developer. It allows you to write powerful, flexible, and cross-browser code with its elegant, well documented, and coherent API.

I'm a big fan of jQuery (as evidenced by my having written both a plug-in and a Dashboard widget for it).

One thing to be aware of is which browsers jQuery supports . The docs site appears to be having issues at the moment. That's another thing to be aware of... ;-)

我已经使用它大约6个月了,除了我的团队中一些较慢的开发人员不接受它(可能是因为一些较长链的令人生畏的外观)我没有碰到一个问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM