我应该从prototype转到jquery吗?

发布于 2024-08-27 08:52:11 字数 1159 浏览 4 评论 0 原文

最后,我一直感觉 jQuery 正在慢慢成为 JS 库中事实上的标准(我可能是错的!),或者至少它比其他框架更活跃。

例如,我一直在寻找像 Componente 这样的优秀开源日历,并发现 http://fullcalendar.vinsol.com / 这是基于 jQuery 的。

我们一直在用 Prototype 做一些很小的事情,比如它的选择器功能(主要是 $ 函数作为 document.getElementById 的快捷方式),当页面已加载并发出一些非常简单的 Ajax 调用。

所以我想迁移应该非常简单,但我想知道从 Prototype 迁移到 jQuery 的优缺点。

另一方面,我认为将它们放在一起并不是一个好的选择,特别是考虑到迁移应该非常简单。我说得对吗?

编辑:一些有用的资源:

Lastly I've been feeling like jQuery is slowly becoming the defacto standard in JS libraries (I might be wrong!), or at least that is more active than the rest of the frameworks.

For example, I've been looking for a fine open source calendar like Componente and found http://fullcalendar.vinsol.com/ which is based on jQuery.

We've been using Prototype for very little things, like its selector capabilities ($ function as a shortcut for document.getElementById, mainly), executing some piece of JS when the page is loaded and to issue some very simple Ajax calls.

So I guess the migration should be quite straight forward, but I'd like to know the pros / cons of migrating from Prototype to jQuery.

On the other hand, I guess that having both of them together is not a good choice, specially taking into account that the migration should be quite simple. Am I right?

Edit: some useful resources:

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

浅紫色的梦幻 2024-09-03 08:52:11

Prototype 和 JQuery 涵盖的领域非常相似。我多年来一直使用 Prototype 作为我的主要 JS 框架,现在我正在迁移到 JQuery。原因如下:

  • JQuery更快。在我见过的所有性能比较中,原型排在最后(随机选择此处)。我也有一个长期的主观印象,即 Prototype 的效果总体上较慢,尤其是在较旧的机器上。

  • JQuery 似乎不仅在 Stack Overflow 上更受欢迎。这意味着获得支持变得更加容易,并且可用插件和现成代码的数量也更多。这不是我的核心原因,但加上 jQuery 是技术上更完善的平台的总体印象,选择就变得显而易见了。

我唯一不喜欢的是:

  • JQuery 代码看起来很糟糕。我非常喜欢 JQuery 及其哲学,但我经常讨厌查看代码。如果有人想出了一种 JQuery 方言,它看起来像普通 JavaScript 一样美观且结构合理,我会很高兴加入。 :)

回复评论:关于我不喜欢 jQuery 编码风格的额外说明。

一言以蔽之:括号。成千上万的人:)

不过说真的。我意识到大部分被认为是“jQuery 风格”的东西都是完全可以选择使用的快捷方式和简写。尽管如此,从代码可读性和可维护性的角度来看,我发现大块 jQuery 代码更难以阅读和理解。是的,随着 jQuery 经验的增长,这会变得容易得多,但是,我希望我的代码即使对于完全的局外人来说也能可读。就这一点而言,在我看来,jQuery 并没有走上正确的方向。大部分代码都是简单的丑陋。这是迄今为止我对这个伟大框架的唯一主要批评。

不过,方法链接,@noah,以及诸如新的 .delay() 之类的东西或者它的名字是什么,我认为完全摇滚。我并不是反对这一点。

Prototype and JQuery cover very similar fields. I have used Prototype as my main JS Framework for many years professionally, and I'm migrating to JQuery. Here's why:

  • JQuery is faster. Prototype comes last in all performance comparisons I've seen (Random pick here). I also have a long-standing subjective impression that Prototype's effects are slower overall, especially on older machines.

  • JQuery seems to be more popular, not only, but also, on Stack Overflow. Which means it is way easier to get support, and the number of available plug-ins and ready-made code is much larger. That's not the central reason for me but together with the overall impression that jQuery is the more technically sound platform, the choice became obvious.

My only dislike is:

  • JQuery code tends to look horrible. I like JQuery and its philosophy very much, but I often hate looking at the code. If somebody came up with a dialect of JQuery that looks as beautiful and structured as plain vanilla JavaScript, I'll gladly be on board. :)

Re the comments: Additional clarification about what I don't like about jQuery's coding style.

In one word: Brackets. Thousands and thousands of them :)

Seriously though. I realize that much of what is considered "jQuery style" are shortcuts and shorthands that are entirely optional to use. Still, from a code readability and maintainability perspective, I find large chunks of jQuery code much more difficult to read and get into. Yes, that will become much easier with growing jQuery experience, but, I want my code to be readable even to a total outsider. In regards to that, jQuery is not going into the right direction IMO. Much of the code is plain ugly. It is my only major criticism of this great framework to date.

Method chaining though, @noah, and stuff like the new .delay() or what its name was, I think totally rock. I'm not saying anything against that.

杯别 2024-09-03 08:52:11

据我所知,Prototype 和 jQuery 大部分是重叠的,只是 jQuery 主要关注 DOM 操作、ajax、事件等,并且并不真正具备 Prototype 所具有的一些功能,如类、继承等。但是,如果你不需要这些东西,只想要一个跨浏览器 DOM manip、ajax、事件等的框架,那么我认为 jQuery 是最好的选择。

As far as i know, Prototype and jQuery mostly overlap, except that jQuery focuses mainly on DOM manipulation, ajax, events, etc, and doesn't really have some of the capabilities that Prototype has, like classes, inheritance, etc. However, if you don't need these things, and only want a framework for cross browser DOM manip, ajax, events, etc, then I think jQuery is the way to go.

呆橘 2024-09-03 08:52:11

您可以同时使用它们。只需在 jQuery 加载后调用 jQuery.noConflict(); 即可。然后你必须编写 jQuery("whatever") 而不是 $("whatever")。 Prototype 提供了许多 jQuery 没有的功能。

然而,Prototype 正在逐渐退出历史舞台。 jQuery 现在是王者,并且有一些很好的理由。如果您想要最新的插件和小部件,jQuery 就会有它们。

Underscore.js 提供与 Prototype 大部分相同的功能,同时不会干扰对象原型和全局命名空间。 Underscore 加上 jQuery 应该可以使从 Prototype 的迁移变得非常简单。

You can use them both together. Just call jQuery.noConflict(); after jQuery loads. Then you'll have to write jQuery("whatever") instead of $("whatever"). Prototype offers a lot of functionality that jQuery does not.

However, Prototype is kind of on the way out. jQuery is king now, and for some pretty good reasons. If you want the latest plugins and widgets, jQuery is going to have them.

Underscore.js offers most of the same functionality as Prototype while not messing with object prototypes and the global namespace. Underscore plus jQuery should make migrating from Prototype pretty straight forward.

一杯敬自由 2024-09-03 08:52:11

直接回答您的问题:是的,您应该切换。是的,你是对的。

我知道你说过你不喜欢括号...你能提供一段你认为漂亮的原型代码片段吗(我将对其进行 jQuery 化以进行比较)?

To answer your questions directly: Yes, you should switch. And yes, you are right.

I know you said you don't like brackets...can you provide a snippet of prototype code that you consider beautiful (I'll jQuery-itize it for comparison)?

凉风有信 2024-09-03 08:52:11

我自 2006 年以来一直在使用 Prototype,我同意 Pekka 对丑陋代码的看法。原型更加优雅。

我一直是 Prototype (+Scriptaculous) 社区的坚定支持者,但遗憾的是,Prototype 正在失去关注度和市场份额。 职业生涯可以建立在了解 jQuery 的基础上,但了解 Prototype 就不行了。

似乎 jQuery 的人似乎更喜欢使用插件,而不知道它们是如何工作的,而 Prototype 的人似乎更核心程序员并倾向于自己构建他们需要的东西。

话虽这么说,我向 jQuery 的过渡并没有那么痛苦。功能大致相同,只是名称不同。还有更多可用的文档和示例代码,使其更易于学习。

框架是移动的目标,有时在速度和功能方面相互超越。一切都在不断进步。 X 比 Y 更好的说法会随着时间的推移而改变,

我认为 Prototype 的可取之处可能是 Scripty2。这是一个使用 Prototype 的令人惊叹的新动画引擎。如果它流行起来(并推向市场,甚至还没有处于测试版),人们对 Prototype 的兴趣可能会重新燃起。除此之外,我认为它永远会有它的支持者,但会从主流中消失。

I have been using Prototype since 2006 and I echo Pekka's feelings about ugly code. Prototype is more elegant.

I have been a staunch supporter of the Prototype (+Scriptaculous) community but sadly, Prototype is losing mindshare and market share. Careers can be built on knowing jQuery, not so much for Prototype.

It seems jQuery people seem to be happier using plug-ins, without knowing how they work, whereas Prototype people seem to be more hard-core programmers and tend to build what they need themselves.

That being said, my transition to jQuery was not all that painful. The functionality is much the same, only with different names. There is a lot more documentation and sample code available, making it easier to pick up.

Frameworks are moving targets, sometimes leap-frogging each other in terms of speed and features. All continue to improve. Saying X is better than Y will change over time

I think Prototype's saving grace may be Scripty2. This is an amazing new animation engine using Prototype. If that catches on (and makes it to market, it's not even in Beta) there may be a resurgence in interest in Prototype. Beyond that I think it will always have its supporters, but will fade away from the mainstream.

゛时过境迁 2024-09-03 08:52:11

如果您想找另一份工作,可以转向 JQuery。如果您关心美观、直观的 JavaScript,请坚持使用原型 - 它不会消失!

if you care about getting another job maybe move to JQuery. If you care about beautiful, intuitive JavaScript stick with prototoype - its not going away!

伪心 2024-09-03 08:52:11

I think the fact that Microsoft has integrated it into the ASP.NET Ajax Framework speaks worlds for jQuery. My current employer standardized on it last year and I can find more job posting specifically asking for jQuery and any other library.

岁月苍老的讽刺 2024-09-03 08:52:11

我认为你应该。我虔诚地使用 jquery,但我不是 Javascript 专业人士。我认为它的易用性是它最强大的功能之一。

I think you should. I use jquery religiously, and I'm not a Javascript Pro. It's ease of use I think, is one of the most powerful things about it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文