TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Why I still prefer Prototype to jQuery

67 点作者 luccastera超过 16 年前

11 条评论

fh超过 16 年前
Not having extensively used either jQuery or Prototype, I found this comparison interesting. But the entire discussion about jQuery "stealing" `this` is somewhat misinformed. Javascript closures don't caputure the value of `this`; instead, the value of `this` is determined at the call site. If the function is called as a method (using the `object.method()` syntax), `this` is bound to `object`; otherwise, `this` is bound to the global object (called `window` in browsers). The behavior I just described makes `this` is almost useless in Javascript closures, and the "idiomatic Prototype" example the author gives cannot possibly work:<p><pre><code> // Prototype $A(this.columns).each(function(item) { this.buildHeader(item); }); </code></pre> If you want to do that, you have explicitly bind `this` to a (differently named) variable in the outer scope:<p><pre><code> var self = this; $A(self.columns).each(function(item) { self.buildHeader(item); });</code></pre>
评论 #431294 未加载
评论 #431273 未加载
评论 #431286 未加载
评论 #431883 未加载
old-gregg超过 16 年前
I don't understand why does one need to make a choice. Even comparing the two makes little sense: jQuery is smaller and DOM-focused, while Prototype is a much more comprehensive multi-file library and DOM-related stuff <i>is just a part of it</i>, completely isolated in its own file which you can exclude during Prototype's build process.<p>I use both: jQuery for HTTP and DOM traversing/manipulation <i>plus</i> DOM-less prototype core for everything else. This combo is awesome, conflict-free and quite compact when gzipped. Bare bone JavaScript is too weak library wise and Prototype makes an excellent "standard library" for it. I couldn't live without Prototype's extensions to enumerable, strings, arrays, hashes, etc.<p>And it's 100% compatible with Rails thanks to jRails project. I highly recommend it.
评论 #431306 未加载
tlrobinson超过 16 年前
<p><pre><code> Determine the index of the first parameter in the Array … Ah, it returns the index. But that’s OK … JavaScript supports the notion of “truthiness”, </code></pre> Except if it returns "0", of course.<p>It's a very C-like way of doing things:<p><pre><code> if ($.inArray(blah blah) &#60; 0) // not found!</code></pre>
评论 #431763 未加载
jkkramer超过 16 年前
It's nice to see a level-headed assessment like this. Too many programmers rely on trends or religious convictions to make decisions. All choices involve trade-offs, so make yourself aware of them!
评论 #431250 未加载
jgfoot超过 16 年前
JavaScript 1.6 added seven new array methods (indexOf, lastIndexOf, every, filter, forEach, map, and some). If only backward compatibility weren't a problem, the warring JavaScript libraries could just use these (or implement them into the prototype like Sugar Arrays, <a href="http://www.dustindiaz.com/sugar-arrays/" rel="nofollow">http://www.dustindiaz.com/sugar-arrays/</a>) instead of creating their own quirky methods.
Caged超过 16 年前
The Prototype <i>this</i> example won't work unless <i>this</i> is bound to the anonymous function, otherwise <i>this</i> is the <i>window</i> object.<p><pre><code> $A(this.columns).each(function(item) { this.buildHeader(item); }.bind(this));</code></pre>
评论 #431300 未加载
larrywright超过 16 年前
I don't have a huge amount of experience with either framework, but I've used them both. One thing that stands out about jQuery is that it's unobtrusive - Prototype is not (at least not without some help from something like Lowpro).
muitocomplicado超过 16 年前
One of his arguments was that prototype is not that slow anymore in comparison to jQuery.<p>Some nice speed improvements are coming to jQuery 1.3:<p><a href="http://www.flickr.com/photos/jeresig/sets/72157612498756067/" rel="nofollow">http://www.flickr.com/photos/jeresig/sets/72157612498756067/</a>
deadwisdom超过 16 年前
jQuery is light, but it has a trove of plugins that will help you with more complex tasks. The core is purposefully limited in scope, not trying to do everything for you; it only provides what Javascript already should, but doesn't.
hs超过 16 年前
i prefer framework that helps me crafting shorter code<p>the last time i used prototype was in 2007, now it's all jquery
GrandMasterBirt超过 16 年前
Argument order:<p>jQuery<p>$.each(collection,function(){ this.bla(); });<p>The reason index is first param is because wheb you need it it is the only param. The reason for the item param is incase you need to attach a scope object to be this!