jQuery 与 javascript?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2340412/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-22 23:51:17  来源:igfitidea点击:

jQuery vs. javascript?

javascriptjquery

提问by Adam Kiss

I recently stumbled upon some javascript forums (sadly, link is lost somewhere in the universe), where you could feel real hate against jQuery for not being... any good?

我最近偶然发现了一些 javascript 论坛(可悲的是,链接在宇宙中的某个地方丢失了),在那里你会真正讨厌 jQuery,因为它不是......有什么好处?

Most arguments seem to make sense actually.

大多数论点实际上似乎都有意义。

Now, I really like jQuery, mostly for letting me concentrate on things I want to do rather on browser inconsistencies and it actually makes AJAXing with cool (or overused?) effects fun.

现在,我真的很喜欢 jQuery,主要是因为它让我专注于我想做的事情而不是浏览器的不一致,它实际上使 AJAXing 与酷(或过度使用?)效果变得有趣。

But if really is something rotten in the core of jQuery, I don't want to rely on it the way I actually... rely on it.

但是,如果 jQuery 的核心真的有些烂,我不想像我实际那样依赖它……依赖它。

I don't want to start yet another argument over which framework is the best... but... Which framework is the best (joke)? As a case usage, think about small to medium web and it's administration.

我不想再开始争论哪个框架是最好的……但是……哪个框架是最好的(笑话)?作为案例用法,请考虑中小型网络及其管理。

I'm just trying to figure out, if stuff in someframework or pure javascript with few mine functions really makes difference.

我只是想弄清楚,如果某些框架中的东西或具有很少我的功能的纯 javascript 真的有什么不同。

Edit:

编辑:

I actually tried to have a normal objective discusssion over pros and cons of:

我实际上试图就以下优点和缺点进行正常的客观讨论:

  1. Using a framework over pure javascript and
  2. jQuery vs. others,
  1. 在纯 javascript 上使用框架和
  2. jQuery 与其他,

Since jQuery seems to be easiest to work with with the quickest learning curve. However, some people just don't understand it and think that I'm starting yet another flame (what I am not). I am actually voting to reopen this question.

因为 jQuery 似乎最容易使用,而且学习曲线最快。然而,有些人就是不理解它,认为我又开始了另一个火焰(我不是什么)。我实际上投票重新打开这个问题。

Also I'm really interested in:

另外我真的很感兴趣:

  • Does jQuery heavily rely on browser sniffing? Could that be a potential problem in the future? Why?
  • I found plenty JS-selector engines, are there any AJAX and FX libraries?
  • Is there any reason (besides browser sniffing and personal "hate" against John Resig) why jQuery is wrong?
  • jQuery 是否严重依赖浏览器嗅探?这可能是未来的潜在问题吗?为什么?
  • 我发现了很多 JS 选择器引擎,有没有 AJAX 和 FX 库?
  • 是否有任何原因(除了浏览器嗅探和个人对 John Resig 的“仇恨”)为什么 jQuery 是错误的?

jQuery actually, as most used, stands for other frameworks also.

实际上,最常用的 jQuery 也代表其他框架。

采纳答案by Xr.

It's all about performance and development speed. Of course, if you are a good programmer and design something that is really tailored to your needs, you might achieve better performance than if you had used a Javascript framework. But do you have the time to do it all by yourself?

这完全取决于性能和开发速度。当然,如果您是一名优秀的程序员并且设计出真正适合您的需求的东西,那么您可能会获得比使用 Javascript 框架更好的性能。但是你有时间自己做这一切吗?

My personal opinion is that Javascript is incredibly useful and overused, but that if you really need it, a framework is the way to go.

我个人的观点是 Javascript 非常有用且被过度使用,但如果你真的需要它,那么框架就是你要走的路。

Now comes the choice of the framework. For what benchmarks are worth, you can find one at http://ejohn.org/files/142/. It also depends on which plugins are available and what you intend to do with them. I started using jQuery because it seemed to be maintained and well featured, even though it wasn't the fastest at that moment. I do not regret it but I didn't test anything else since then.

现在是框架的选择。对于基准测试的价值,您可以在http://ejohn.org/files/142/ 上找到一个。它还取决于可用的插件以及您打算用它们做什么。我开始使用 jQuery 是因为它似乎得到了维护和很好的功能,尽管当时它并不是最快的。我不后悔,但从那以后我没有测试任何其他东西。

回答by CMJ

Personally i think you should learn the hard way first. It will make you a better programmer and you will be able to solve that one of a kind issue when it comes up. After you can do it with pure JavaScript then using jQuery to speed up development is just an added bonus.

我个人认为你应该先学习艰难的方法。它会让你成为一个更好的程序员,当它出现时,你将能够解决这个问题。在您可以使用纯 JavaScript 完成之后,使用 jQuery 加速开发只是一个额外的好处。

If you can do it the hard way then you can do it the easy way, it doesn't work the other way around. That applies to any programming paradigm.

如果你能以困难的方式做到,那么你就可以以简单的方式做到,反之则行不通。这适用于任何编程范式。

回答by Diogo Schneider

"I actually tried to had a normal objective discusssion over pros and cons of 1., using framework over pure javascriptand 2., jquery vs. others, since jQuery seems to be easiest to work with with quickest learning curve."

“我实际上试图对 1. 的优缺点进行正常的客观讨论,使用框架而不是纯 javascript和 2.,jquery 与其他,因为 jQuery 似乎最容易使用,学习曲线最快。”

Using any frameworkbecause you don't want to actually learn the underlying language is absolutely wrong not only for JavaScript, but for any other programming language.

因为不想真正学习底层语言而使用任何框架是绝对错误的,不仅对于 JavaScript,对于任何其他编程语言也是如此。

"Is there any reason (besides browser sniffing and personal "hate" against John Resig) why jQuery is wrong?"

“有什么理由(除了浏览器嗅探和个人对 John Resig 的“仇恨”)为什么 jQuery 是错误的?”

Most of the hate agains it comes from the exaggerated fanboyism which pollutes forums with "use jQuery" as an answer for every single JavaScript question and the overuse which produces code in which simple statements such as declaring a variable are done through library calls.

对它的大部分仇恨来自夸大的狂热分子,它通过“使用 jQuery”作为每个 JavaScript 问题的答案来污染论坛,以及过度使用产生的代码,其中的简单语句(例如声明变量)是通过库调用完成的。

Nevertheless, there are also some legit technical issues such as the shared guilt in producing illegible code and overhead. Of course those two are aggravated by the lack of developer proficiency rather than the library itself.

尽管如此,也存在一些合法的技术问题,例如在产生难以辨认的代码和开销方面的共同罪恶感。当然,由于缺乏开发人员的熟练程度而不是库本身,这两种情况更加严重。

回答by Mahesh Velaga

Jquery like any other good JavaScript frameworks supplies you with functionality independent of browser platform wrapping all the intricacies, which you may not care about or don't want to care about.

Jquery 像任何其他优秀的 JavaScript 框架一样,为您提供独立于浏览器平台的功能,其中包含您可能不关心或不想关心的所有错综复杂的问题。

I think using a framework is better instead of using pure JavaScript and doing all the stuff from scratch, unless you usage is very limited.

我认为使用框架比使用纯 JavaScript 并从头开始做所有事情更好,除非您的使用非常有限。

I definitely recommend JQuery!

我绝对推荐JQuery!

Thanks

谢谢

回答by Rich Bradshaw

  • Does jQuery heavily rely on browser sniffing? Could be that potential problem in future? Why?
  • jQuery 是否严重依赖浏览器嗅探?将来可能是那个潜在的问题吗?为什么?

No - there is the $.browser method, but it's deprecated and isn't used in the core.

不 - 有 $.browser 方法,但它已被弃用且未在核心中使用。

  • I found plenty JS-selector engines, are there any AJAX and FX libraries?
  • 我发现了很多 JS 选择器引擎,有没有 AJAX 和 FX 库?

Loads. jQuery is often chosen because it does AJAX and animations well, and is easily extensible. jQuery doesn't use it's own selector engine, it uses Sizzle, an incredibly fast selector engine.

负载。通常选择 jQuery 是因为它可以很好地执行 AJAX 和动画,并且易于扩展。jQuery 不使用它自己的选择器引擎,它使用Sizzle,一个非常快的选择器引擎。

  • Is there any reason (besides browser sniffing and personal "hate" against John Resig) why jQuery is wrong?
  • 是否有任何原因(除了浏览器嗅探和个人对 John Resig 的“仇恨”)为什么 jQuery 是错误的?

No - it's quick, relatively small and easy to extend.

不 - 它很快,相对较小且易于扩展。

For me personally it's nice to know that as browsers include more stuff (classlist API for example) that jQuery will update to include it, meaning that my code runs as fast as possible all the time.

就我个人而言,很高兴知道随着浏览器包含更多内容(例如类列表 API),jQuery 将更新以包含它,这意味着我的代码始终运行得尽可能快。

Read through the source if you are interested, http://code.jquery.com/jquery-1.4.3.js- you'll see that features are added based on the best case first, and gradually backported to legacy browsers - for example, a section of the parseJSON method from 1.4.3:

如果您有兴趣,请通读源代码,http://code.jquery.com/jquery-1.4.3.js- 您将看到首先根据最佳情况添加功能,然后逐渐向后移植到旧版浏览器 - 对于例如,来自 1.4.3 的 parseJSON 方法的一部分:

return window.JSON && window.JSON.parse ?
    window.JSON.parse( data ) :
    (new Function("return " + data))();

As you can see, if window.JSON exists, the browser uses the native JSON parser, if not, then it avoids using eval (because otherwise minfiers won't minify this bit) and sets up a function that returns the data. This idea of assuming modern techniques first, then degrading to older methods is used throughout meaning that new browsers get to use all the whizz bang features without sacrificing legacy compatibility.

如您所见,如果 window.JSON 存在,则浏览器使用本机 JSON 解析器,如果不存在,则避免使用 eval(因为否则 minfiers 不会缩小该位)并设置返回数据的函数。这种首先采用现代技术,然后降级为旧方法的想法贯穿始终,这意味着新浏览器可以在不牺牲遗留兼容性的情况下使用所有 whiz bang 功能。

回答by Starx

Jquery VS javascript, I am completely against the OP in this question. Comparison happens with two similar things, not in such case.

Jquery VS javascript,我完全反对这个问题中的 OP。比较发生在两个相似的事情上,而不是在这种情况下。

Jquery is Javascript. A javascript library to reduce vague coding, collection commonly used javascript functions which has proven to help in efficient and fast coding.

Jquery 是 Javascript。一个 javascript 库,用于减少模糊编码,收集常用的 javascript 函数,已被证明有助于高效和快速编码。

Javascript is the source, the actual scripts that browser responds to.

Javascript 是源代码,浏览器响应的实际脚本。