简体   繁体   English

什么是jQuery的限制?

[英]What are jQuery's limitations?

Joel always said to be careful when using 3rd party libraries. Joel总是说在使用第三方库时要小心。 From my initial impressions, jQuery is great. 从我最初的印象来看,jQuery很棒。 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. 我遇到了一些错误,我必须为自己找到一个快速解决方案,然后使用下一个jQuery版本进行额外的测试,以确保错误已得到妥善处理,但这适用于任何第三方库而不仅仅是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. 我认为这是一个非常棒的图书馆,我必须说,虽然有关第三方图书馆的建议有其优点,但是在这个Web 2.0世界中,Javascript的使用量已经飙升,并且浏览器之间存在很多差异,拥有一个维护良好的库可以真正加快开发速度,因为它可以节省您自己完成所有腿部工作的开销。

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. 我想如果我要发出一个警告,那就是确保你不要过度使用它 - 虽然它真的通过抽象掉你不需要担心的大量逻辑来加速Javascript开发,总是存在风险你会开始编写效率低下的应用程序,因为你没有意识到你在浏览器上的确切要求。 I would therefore advise you do plenty of profiling with the likes of Firebug to check what's going on under the hood. 因此,我建议你使用Firebug等方法进行大量分析,以检查引擎盖下的情况。

@ mjc @ mjc

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

And/or define a variable, for which to use the jQuery functions on: 和/或定义一个变量,为其使用jQuery函数:

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. 我在jQuery中遇到的一件事是,你最终将很多项目链接在一起,如果你不小心,它很快就会变得难以理解。

an example I can think of that illustrates this is on John David Anderson's blog : 我能想到的一个例子说明这是在John David Anderson的博客上

There's a guy who wrote a logging function so you can figure out whereYou(are).whenYoureCoding().inThe(middleOf).a(jQuery).trainWreck(). 有一个人写了一个记录功能,你可以弄清楚你在哪里.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. jQuery很棒 - 它可以做任何javascript可以做的事情,但更快,并且代码更少。 Its only limitations are the ones inherent in javascript as a client-side scripting language. 它唯一的局限是javascript中作为客户端脚本语言固有的限制。 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: 它不是jQuery中的限制,但使用jQuery时使用ASP.NET开发人员时常犯错误:

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

@ BrilliantWinter @ BrilliantWinter

jQuery is not at all bloated. jQuery并不臃肿。 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对象的扩展,这意味着你可以分离你不使用的任何功能,并使库的占用空间甚至小于它的默认大小(15kb,Minified和Gzipped)。

jQuery - and every other library for that matter - provides an API which is the same across all A-grade browsers. jQuery - 以及其他所有库 - 提供了一个API,它在所有A级浏览器中都是相同的。 This abstraction leaves your code cleaner and less error-prone. 这种抽象使您的代码更清晰,更不容易出错。

Finally, jQuery is used by major "players". 最后,jQuery被主要的“玩家”使用。 Companies like Google, Dell, Digg and NBC use the library. Google,Dell,Digg和NBC等公司都使用该库。 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. 这不仅是一个很大的批准,而且还保证jQuery的开发人员在修改库时非常小心,确保没有任何中断并且没有引入错误。

@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. @BrilliantWater - 大多数人不使用jQuery“学习”,他们使用它是因为它更快更容易使用,并且比自己创建所有方法引起的麻烦更少。 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. jQuery是最小的库之一,随着越来越多的人获得宽带,它变得越来越少。

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是由GoogleCode托管的,因此很可能它已经存在于用户缓存中,因为很多网站都使用它!

jQuery is awesome! jQuery太棒了! I keep saying to myself that I need to learn another library but I really don't. 我一直对自己说,我需要学习另一个图书馆,但我真的没有。 jQuery has everything I need. jQuery拥有我需要的一切。 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. 我发现jQuery在编写任何有用的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. 我建议不要使用flash,而是执行相对“简单”的动画,jQuery与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. 最后,浏览器处理得太多了(特别是IE,但是FF显示出压力的迹象),我们不得不将其几乎全部扩展回来。

jQuery is tons of fun to code with, and experiment with. jQuery很有趣,可以用来编写代码并进行实验。 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. jQuery的唯一缺点是它太简单易用。 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. 除此之外,jQuery非常漂亮,由天才和他的聪明程序员组成,可确保跨浏览器质量,减少开发人员的工作量。 Can't go wrong. 不能出错。 If you don't like jQuery, you are a little bit off and probably don't bathe often enough. 如果你不喜欢jQuery,你有点偏离,可能不经常洗澡。

UPDATE 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. 如果使用querySelector和MDN引用,jQuery实际上已经不再需要了,因为浏览器已经融合到大多数情况下是相同的,除非你当然仍然生活在IE8的死亡土地要求中。 jQuery also lives globally which is bad if you are building modern JavaScript. jQuery也存在于全球范围内,如果你正在构建现代JavaScript,那就很糟糕。 jQuery is not really useful at this point aside from having some old school plugins not using modular syntax libraries. 除了让一些旧的学校插件不使用模块化语法库之外,jQuery在这一点上并不是真正有用。

Start to look toward modularizing JavaScript as that was the trend after jQuery. 开始关注模块化JavaScript,因为这是jQuery之后的趋势。 Pay attention to es6/es2015. 注意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. 开始使用React / React Native OR Angular 2来制作应用程序,因为它在某种程度上达到了目标。

Sorry, John Resig. 对不起,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. 如果jQuery不适合,你总是可以考虑不同的框架。 Here's an example of mootools . 这是一个mootools的例子。

MooTools is a compact, modular, Object-Oriented JavaScript framework designed for the intermediate to advanced JavaScript developer. MooTools是一个紧凑的,模块化的,面向对象的JavaScript框架,专为中高级JavaScript开发人员而设计。 It allows you to write powerful, flexible, and cross-browser code with its elegant, well documented, and coherent API. 它允许您使用其优雅,文档齐全且连贯的API编写功能强大,灵活且跨浏览器的代码。

I'm a big fan of jQuery (as evidenced by my having written both a plug-in and a Dashboard widget for it). 我是jQuery的忠实粉丝(我已经为它编写了一个插件和一个Dashboard小部件证明了这一点)。

One thing to be aware of is which browsers jQuery supports . 需要注意的一件事是jQuery支持哪些浏览器 The docs site appears to be having issues at the moment. 文档网站目前似乎有问题。 That's another thing to be aware of... ;-) 这是另一件需要注意的事情...... ;-)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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