原型 VS jQuery - 优点和缺点?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2644556/
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-26 13:56:49  来源:igfitidea点击:

Prototype VS jQuery - Strengths and Weaknesses?

jqueryprototypejsria

提问by Luca Filosofi

I don't want to open another "Yet Another Js VS Js" thread.

我不想打开另一个“ Yet Another Js VS Js”主题。

I guess, in the end Prototype and jQuery are both JS and have almost the same methods and functions and need almost the same lines of code for identical tasks.

我想,最终 Prototype 和 jQuery 都是 JS,并且具有几乎相同的方法和功能,并且需要几乎相同的代码行来完成相同的任务。

For a real Rich Internet Application, what are the real strengthsand what the weaknessesin Prototype vs. jQuery?

对于真正的富互联网应用程序,Prototype 与 jQuery的真正优势劣势是什么?

回答by Graza

I initially liked the idea of Prototype's extending elements with new or modified methods.

我最初喜欢 Prototype 使用新方法或修改方法扩展元素的想法。

However, I've discovered a number of reasons this is a bad thing (TM)

但是,我发现了很多原因,这是一件坏事 (TM)

Do some googling and you'll probably find some other reasons, but the primary reason is that Prototype cannot be guaranteed to "play nice" with other frameworks or libraries, as other libraries expect the behaviour of elements and methods to be "standard", and due to the things Prototype does, you may find a number of things that are broken by it.

做一些谷歌搜索,你可能会发现其他一些原因,但主要原因是 Prototype 不能保证与其他框架或库“玩得很好”,因为其他库期望元素和方法的行为是“标准的”,由于 Prototype 所做的事情,您可能会发现许多被它破坏的东西。

The most recent example I discovered was Prototype screwing with JSON and stringify. I was using EasyXDM, and it simply did not work in some cases where the prototype.js library was loaded. As I was writing a framework to be used by others, and thus did not have control over the content of the page, I needed to create and do everything in an IFRAME in order to ensure things such as prototype.js did not play havoc with what I was trying to do.

我最近发现的一个例子是使用 JSON 和 stringify 的 Prototype。我使用的是 EasyXDM,但在加载prototype.js 库的某些情况下它根本不起作用。由于我正在编写一个供其他人使用的框架,因此无法控制页面的内容,因此我需要在 IFRAME 中创建和执行所有操作,以确保诸如prototype.js 之类的东西不会破坏我想做什么。

...so jQuery wins hands-down for me, because I just don't think its right for a framework to automatically screw with the standard behaviour of the DOM and javascript. YOU should be in control of these things, Prototype takes some of this control away from you....

...所以 jQuery 对我来说毫无悬念,因为我认为框架不适合自动与 DOM 和 javascript 的标准行为相冲突。你应该控制这些事情,Prototype 从你那里拿走了一些这种控制......

回答by Nick Craver

I use jQuery over prototype as well, just look at the top of this page for why:

我也在原型上使用 jQuery,看看这个页面的顶部为什么:

jquery tagged questions: 531,752
prototype tagged question: 2,465
Updated 9/22/2014, on 12/14/2011 jQuery - 135,641 / prototype - 2,327

jquery 标记问题531,752
原型标记问题2,465
2014 年 9 月 22 日更新,2011 年 14 月 12 日 jQuery - 135,641 / 原型 - 2,327

jQuery is very terse, concise code. Prototype I find much more verbose, though often equivalent in many areas for functionality. However if you need help getting started, you want the larger community. More support, more of the same questions you'll have already out there answered and easy to google, and more plug-ins, code you're probably looking for to do something...already written.

jQuery 是非常简洁的代码。原型我发现要冗长得多,尽管在许多功能方面通常是等效的。但是,如果您需要入门帮助,则需要更大的社区。更多的支持,更多相同的问题,你已经在那里得到了回答并且很容易用谷歌搜索,更多的插件,你可能正在寻找做某事的代码......已经写好了。

For the same reasons, the larger the community, the more code, the more complexcode, meaning that the simple stuff has been written and many complicated situations solved as well, chances are if you're writing a very rich application you're going to run into some pretty complicated questions or situations...there are more resources out there to help you handle this.

出于同样的原因,社区越大,代码越多,代码越复杂,这意味着已经编写了简单的东西并解决了许多复杂的情况,如果您正在编写一个非常丰富的应用程序遇到一些非常复杂的问题或情况……有更多资源可以帮助您解决这个问题。

Again...for the same community size reason, more deficiencies in the framework have been found and the gaps filled, because a larger community was scrutinizing it. This means that when you come across a problem, chances are someone else did too, and some method or option was added to keep you moving, not jammed up because you hit something the framework couldn't do.

再次......出于相同的社区规模原因,在框架中发现了更多缺陷并填补了空白,因为更大的社区正在它。这意味着当您遇到问题时,很可能其他人也遇到了问题,并且添加了一些方法或选项来让您继续前进,而不是因为遇到框架无法做到的事情而陷入困境。

回答by Mark

I'm currently rewriting large blocks off an application to move from Prototype to jQuery. Why? Plugins, plugins, plugins, particularly UI widgets. Prototype UI elements are rather fragmented and very piecemeal, while jQuery has a very rich set of "standard" elements.

我目前正在重写应用程序的大块以从 Prototype 移动到 jQuery。为什么?插件,插件,插件,尤其是 UI 小部件。原型 UI 元素相当零散且非常零散,而 jQuery 有一组非常丰富的“标准”元素

回答by fdreger

JQuery was built to make adding fancy effects to pages easy. It has achieved a 100% success.

JQuery 旨在使向页面添加奇特效果变得容易。它取得了 100% 的成功。

Since adding animations and occasional ajax calls is what people usually need and demand from a Javascript library, JQuery has a large community. The JQuery motto is "I'll add some sparkle, and get out of the way", which is exactly what we, developers, often need.

由于添加动画和偶尔的 ajax 调用是人们通常需要和要求的 Javascript 库,因此 JQuery 拥有庞大的社区。JQuery 的座右铭是“我会添加一些亮点,然后让开”,这正是我们开发人员经常需要的。

Nevertheless Prototype excels at most other use-cases. It has a stable framework for class-based OOP (uniformly solving problems like inheriting constructors), and a good set of general use abstractions to deal with data.

尽管如此,Prototype 在大多数其他用例中表现出色。它有一个稳定的基于类的 OOP 框架(统一解决继承构造函数等问题),以及一组很好的通用抽象来处理数据。

回答by Mickel

I chose jQuery over Prototype because:

我选择 jQuery 而不是 Prototype,因为:

  • the "do more, write less..."
  • the jQuery community is bigger (hence, more plugins and resources)
  • “多做,少写……”
  • jQuery 社区更大(因此有更多的插件和资源)

回答by Chris

I have used both and like both. It really depends on your project's requirements. To me, it seems like both platforms came from 2 different directions because of 2 different requirements. They were both created out of the need to solve programming issues to help build websites/applications faster and better.

我两个都用过,都喜欢。这实际上取决于您的项目要求。对我来说,由于 2 个不同的要求,这两个平台似乎来自 2 个不同的方向。它们都是出于解决编程问题以帮助更快更好地构建网站/应用程序的需要而创建的。

When making websites quickly, with a standard tool box of tricks, jquery and its library is great. No sense in reinventing the wheel. I do, however, run into the odd browser version issue when my tool/trick is not working and it always happens that it is the client who has that specific version. Usually happens when a browser version is released/updated. So, I then have to go fetch the new release of that jquery library file to update all my sites, that is if the community has already noticed and resolved said issue. This is my only peeve because I do not have the time to figure it out myself. It does not happen often but does happen.

在快速制作网站时,使用标准的技巧工具箱,jquery 及其库非常棒。重新发明轮子毫无意义。但是,当我的工具/技巧不起作用时,我确实遇到了奇怪的浏览器版本问题,并且总是发生具有该特定版本的客户端。通常在浏览器版本发布/更新时发生。所以,然后我必须去获取那个 jquery 库文件的新版本来更新我的所有网站,也就是说,如果社区已经注意到并解决了上述问题。这是我唯一的烦恼,因为我没有时间自己弄清楚。它不经常发生,但确实发生了。

When working on more complex web projects, maybe a network of sites supported with back-end APIs, then I find prototype is great. I take full advantage of server side OO coding and was very pleased that I can do the same with Prototype. I feel like I have more "control" over my applications and can fix things quickly as I am the author. I do hear what people are saying about overhead, DOMs extended, etc. but I have not run into any majors issues (knock on wood). Also, the whole issue to not having a 'for each' statement is not much of an problem when I can just as easily iterate the same variable with .each(function(){},..) and with a little more control.

在处理更复杂的 Web 项目时,可能是后端 API 支持的站点网络,然后我发现原型很棒。我充分利用了服务器端 OO 编码,并且很高兴我可以用 Prototype 做同样的事情。我觉得我对我的应用程序有更多的“控制”并且可以快速修复问题,因为我是作者。我确实听到了人们对开销、DOM 扩展等的看法,但我没有遇到任何专业问题(敲木头)。此外,当我可以轻松地使用 .each(function(){},..) 迭代同一个变量并有更多控制时,没有“for each”语句的整个问题并不是什么大问题。

So, each one has its place and you have to pick your own drug.

所以,每一种都有它的位置,你必须选择你自己的药物。

Like,

喜欢,

回答by Sarfraz

Neither is the "best". It's all depends. Try them both and see which one you like more. I personally use JQuery due to ease-of-useover prototype which is rather advanced and has longer learning curve.

也不是“最好的”。这一切都取决于。两个都试一下,看看你更喜欢哪一个。我个人使用 JQuery 是因为它比原型更易于使用,原型相当先进并且学习曲线更长。

Have a look at:

看一下:

Prototype vs JQuery (at Ajaxian)

原型 vs JQuery(在 Ajaxian)

回答by Alsciende

This is another interesting article about jQuery and MooTools (MooTools and Prototype are mostly interchangeable, at least within the context of this debate) : http://jqueryvsmootools.com/

这是另一篇关于 jQuery 和 MooTools 的有趣文章(MooTools 和 Prototype 大多可以互换,至少在这次辩论的背景下):http: //jqueryvsmootools.com/

回答by Illuin

jQueryuses CSS-style selectors and filters which are based on CSS syntax. From a design standpoint, this has a lot of benefits. I'm very fond of and proficient at CSS, so jQueryfeels right at home for me personally. If you are looking for a syntax so your all-around coding experience is more pleasant, and you're a big fan of/proficient at CSS, it's safe to say you will prefer jQueryover the alternatives. I took a basic course in Prototypeand I was bored to tears. I've just completed "The Essentials of jQuery"over at Lynda'sand I absolutely love it, because of it's close relationship with CSS. I've been programming in vanilla JavaScript for about 10 years and I have always found it to be extremely dry; and to me it's code overkill(not much bang for the buck). Though it's been very useful to me over the years. From what I've seen so far, jQueryis what JavaScript SHOULD HAVE been from day one. But then again, it takes a lot of time, testing, and effort to improve things. So jQuery wins for me.

jQuery使用基于 CSS 语法的 CSS 样式选择器和过滤器。从设计的角度来看,这有很多好处。我非常喜欢并精通 CSS,因此jQuery对我个人来说感觉很合适。如果您正在寻找一种语法,以便您的全面编码体验更加愉快,并且您是 CSS 的忠实粉丝/精通 CSS,那么可以肯定地说,您会更喜欢jQuery而不是替代品。我参加了Prototype的基础课程,我无聊到流泪。我刚刚在Lynda's完成了“jQuery 基础”我非常喜欢它,因为它与 CSS 有着密切的关系。我已经用普通 JavaScript 编程大约 10 年了,但我总是发现它非常枯燥;对我来说,这是代码矫枉过正(物超所值)。尽管这些年来它对我非常有用。从我目前所见,jQuery就是 JavaScript 从第一天起就应该拥有的东西。但话又说回来,需要花费大量时间、测试和努力来改进事物。所以 jQuery 为我赢了。

回答by Clint

I'm not experienced in jQuery or Prototype, yet. About to start learning one of them to add to my toolbox as a Senior ColdFusion Developer & project manager. My take on this is initially which one a new comer will decide on as this reflects industry adoptation, which IMHO is key.

我还没有使用 jQuery 或 Prototype 的经验。即将开始学习其中一个作为高级 ColdFusion 开发人员和项目经理添加到我的工具箱中。我对此的看法最初是新来者将决定哪个,因为这反映了行业的采用,恕我直言是关键。

Based on a quick look around and a few tutorial reads on both, it seems they each offer the same core abilities. However, looking at job boards and other projects, jQuery seems to be in much more "demand" as opposed to just a skill one can use. To me, jQuery wins here with adoption and demand, community support and documentation is a plus. Nothing against Prototype, it's good to know if a project requires it due to pre existence because some developer picked it as the first one he looked into.

基于快速浏览和阅读一些关于两者的教程,似乎它们每个都提供相同的核心能力。然而,看看求职板和其他项目,jQuery 似乎有更多的“需求”,而不仅仅是一种可以使用的技能。对我来说,jQuery 在这里赢得了采用和需求,社区支持和文档是一个加分项。没有什么反对 Prototype,很高兴知道一个项目是否因为预先存在而需要它,因为一些开发人员选择它作为他研究的第一个。