<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Prototype&#039;s Array.any/all with jQuery</title>
	<atom:link href="http://www.barneyb.com/barneyblog/2008/05/08/prototypes-array-dot-all-with-jquery/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.barneyb.com/barneyblog/2008/05/08/prototypes-array-dot-all-with-jquery/</link>
	<description>Thoughts, rants, and even some code from the mind of Barney Boisvert.</description>
	<lastBuildDate>Thu, 11 Sep 2014 09:58:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Andy</title>
		<link>https://www.barneyb.com/barneyblog/2008/05/08/prototypes-array-dot-all-with-jquery/comment-page-1/#comment-410864</link>
		<dc:creator>Andy</dc:creator>
		<pubDate>Wed, 02 Oct 2013 15:08:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=391#comment-410864</guid>
		<description>&lt;pre&gt;(function(window, $, undefined) {
  $.fn.all = function(callback) {
    var all = true;
    this.each(function() {
      if ( !callback.call(this) ) {
        all = false;
        return false;
      }
    });
    return all;
  };
  $.fn.any = function(callback) {
    var any = false;
    this.each(function() {
      if ( !!callback.call(this) ) {
        any = true;
        return false;
      }
    });
    return any;
  };
})(this, jQuery);
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<pre>(function(window, $, undefined) {
  $.fn.all = function(callback) {
    var all = true;
    this.each(function() {
      if ( !callback.call(this) ) {
        all = false;
        return false;
      }
    });
    return all;
  };
  $.fn.any = function(callback) {
    var any = false;
    this.each(function() {
      if ( !!callback.call(this) ) {
        any = true;
        return false;
      }
    });
    return any;
  };
})(this, jQuery);
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: JDD</title>
		<link>https://www.barneyb.com/barneyblog/2008/05/08/prototypes-array-dot-all-with-jquery/comment-page-1/#comment-88029</link>
		<dc:creator>JDD</dc:creator>
		<pubDate>Mon, 12 May 2008 13:46:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=391#comment-88029</guid>
		<description>Prototype&#039;s addition of document.getElementsByClassName() is deprecated and it is encouraged to use $$() instead.

They returned the results $A&#039;d to support chaining.
Prototype created the document.getElementsByClassName function before it was even marked for addition in the effected browsers.

- JDD</description>
		<content:encoded><![CDATA[<p>Prototype's addition of document.getElementsByClassName() is deprecated and it is encouraged to use $$() instead.</p>
<p>They returned the results $A'd to support chaining.<br />
Prototype created the document.getElementsByClassName function before it was even marked for addition in the effected browsers.</p>
<p>- JDD</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: barneyb</title>
		<link>https://www.barneyb.com/barneyblog/2008/05/08/prototypes-array-dot-all-with-jquery/comment-page-1/#comment-87466</link>
		<dc:creator>barneyb</dc:creator>
		<pubDate>Sat, 10 May 2008 20:49:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=391#comment-87466</guid>
		<description>Matt,

Interesting.  It&#039;s surprising that Prototype opted to return the $A()-ed result; I would not have expected that.  But as the article points out, now that $$() is around, getElementsByClassName is basically unnecessary.    Not going to help existing code, of course.</description>
		<content:encoded><![CDATA[<p>Matt,</p>
<p>Interesting.  It's surprising that Prototype opted to return the $A()-ed result; I would not have expected that.  But as the article points out, now that $$() is around, getElementsByClassName is basically unnecessary.    Not going to help existing code, of course.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt W.</title>
		<link>https://www.barneyb.com/barneyblog/2008/05/08/prototypes-array-dot-all-with-jquery/comment-page-1/#comment-87414</link>
		<dc:creator>Matt W.</dc:creator>
		<pubDate>Sat, 10 May 2008 18:00:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=391#comment-87414</guid>
		<description>They did do that, but here is an article that discussed the problems that happened when getElementsByClassName went native - 

http://ejohn.org/blog/getelementsbyclassname-pre-prototype-16/</description>
		<content:encoded><![CDATA[<p>They did do that, but here is an article that discussed the problems that happened when getElementsByClassName went native &#8211; </p>
<p><a href="http://ejohn.org/blog/getelementsbyclassname-pre-prototype-16/" rel="nofollow">http://ejohn.org/blog/getelementsbyclassname-pre-prototype-16/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: barneyb</title>
		<link>https://www.barneyb.com/barneyblog/2008/05/08/prototypes-array-dot-all-with-jquery/comment-page-1/#comment-87387</link>
		<dc:creator>barneyb</dc:creator>
		<pubDate>Sat, 10 May 2008 16:40:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=391#comment-87387</guid>
		<description>Matt,

I haven&#039;t actually checked, but I&#039;d be utterly shocked if Prototype didn&#039;t do this:

&lt;code&gt;if (! document.getElementsByClassName) {
document.getElementsByClassName = function(...) {...}
}&lt;/code&gt;

It&#039;s about making browsers consistent, not overriding built-in functionality (unless it&#039;s incorrect).  So you use the native implementation wherever you can, supply a non-native one wherever it&#039;s needed, and have a consistent interface across browsers.</description>
		<content:encoded><![CDATA[<p>Matt,</p>
<p>I haven't actually checked, but I'd be utterly shocked if Prototype didn't do this:</p>
<p><code>if (! document.getElementsByClassName) {<br />
document.getElementsByClassName = function(...) {...}<br />
}</code></p>
<p>It's about making browsers consistent, not overriding built-in functionality (unless it's incorrect).  So you use the native implementation wherever you can, supply a non-native one wherever it's needed, and have a consistent interface across browsers.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt W.</title>
		<link>https://www.barneyb.com/barneyblog/2008/05/08/prototypes-array-dot-all-with-jquery/comment-page-1/#comment-87369</link>
		<dc:creator>Matt W.</dc:creator>
		<pubDate>Sat, 10 May 2008 15:35:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=391#comment-87369</guid>
		<description>I see what you are saying, but my point was that because prototype added the getElementsByClassName method to the document object, it will overwrite the native implementation in Firefox 3.  The native implementation should always be significantly faster.  If jQuery were add  to the grep method to the Array object directly, it would overwrite any future native grep method.</description>
		<content:encoded><![CDATA[<p>I see what you are saying, but my point was that because prototype added the getElementsByClassName method to the document object, it will overwrite the native implementation in Firefox 3.  The native implementation should always be significantly faster.  If jQuery were add  to the grep method to the Array object directly, it would overwrite any future native grep method.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: barneyb</title>
		<link>https://www.barneyb.com/barneyblog/2008/05/08/prototypes-array-dot-all-with-jquery/comment-page-1/#comment-87183</link>
		<dc:creator>barneyb</dc:creator>
		<pubDate>Fri, 09 May 2008 23:34:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=391#comment-87183</guid>
		<description>Matt,

&lt;code&gt;document.getElementById(&quot;id&quot;)&lt;/code&gt; is requesting element from the document object.  &lt;code&gt;document.getElementsByClassName(&quot;name&quot;)&lt;/code&gt; is requesting elements from the document.  Those are both the &quot;right&quot; way, in my view.  CF doesn&#039;t have a direct corollary, but one could consider &lt;code&gt;xmlSearch(document, &quot;//*[@class=&#039;name&#039;&quot;)&lt;/code&gt; to be very much the same thing (returning a list of elements from the document with the specified class name).  Note the inversion of where the behaviour lives (on the object itself vs. in a global function).

So getElementsByClassName follows the standard OO-like nature of JS.</description>
		<content:encoded><![CDATA[<p>Matt,</p>
<p><code>document.getElementById("id")</code> is requesting element from the document object.  <code>document.getElementsByClassName("name")</code> is requesting elements from the document.  Those are both the "right" way, in my view.  CF doesn't have a direct corollary, but one could consider <code>xmlSearch(document, "//*[@class='name'")</code> to be very much the same thing (returning a list of elements from the document with the specified class name).  Note the inversion of where the behaviour lives (on the object itself vs. in a global function).</p>
<p>So getElementsByClassName follows the standard OO-like nature of JS.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt W.</title>
		<link>https://www.barneyb.com/barneyblog/2008/05/08/prototypes-array-dot-all-with-jquery/comment-page-1/#comment-87182</link>
		<dc:creator>Matt W.</dc:creator>
		<pubDate>Fri, 09 May 2008 23:25:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=391#comment-87182</guid>
		<description>I believe jQuery does it for forward compatibility.  See prototype using getElementsByClassName which is now native to Firefox 3.</description>
		<content:encoded><![CDATA[<p>I believe jQuery does it for forward compatibility.  See prototype using getElementsByClassName which is now native to Firefox 3.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: barneyb</title>
		<link>https://www.barneyb.com/barneyblog/2008/05/08/prototypes-array-dot-all-with-jquery/comment-page-1/#comment-87116</link>
		<dc:creator>barneyb</dc:creator>
		<pubDate>Fri, 09 May 2008 18:10:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=391#comment-87116</guid>
		<description>Patrick,

Good call on grep(), that definitely makes the objective more clear.

I&#039;ll have to take a deeper look at the Collection plugin, but I really don&#039;t see what&#039;s wrong with modifying the Array prototype.  JavaScript (and ECMAScript) are specifically designed so that you can extend functionality that way - why not leverage it and make you code simpler?

Maybe it&#039;s just the OO guy in me, but it annoys me that jQuery and CF share &quot;separate state and behaviour&quot; paradigm, and while CF does it for backwards compatibility, jQuery doesn&#039;t have an excuse.  Why should I have to supply my &quot;something&quot; to some external procedure to add behaviour, why can&#039;t I just ask the &quot;something&quot; directly?

CF: &lt;code&gt;arrayLen(myArray);&lt;/code&gt; vs. &lt;code&gt;myArray.length;&lt;/code&gt;

jQuery: &lt;code&gt;jQuery.grep(myArray, function(){});&lt;/code&gt; vs. &lt;code&gt;myArray.grep(function(){});&lt;code&gt;</description>
		<content:encoded><![CDATA[<p>Patrick,</p>
<p>Good call on grep(), that definitely makes the objective more clear.</p>
<p>I'll have to take a deeper look at the Collection plugin, but I really don't see what's wrong with modifying the Array prototype.  JavaScript (and ECMAScript) are specifically designed so that you can extend functionality that way &#8211; why not leverage it and make you code simpler?</p>
<p>Maybe it's just the OO guy in me, but it annoys me that jQuery and CF share "separate state and behaviour" paradigm, and while CF does it for backwards compatibility, jQuery doesn't have an excuse.  Why should I have to supply my "something" to some external procedure to add behaviour, why can't I just ask the "something" directly?</p>
<p>CF: <code>arrayLen(myArray);</code> vs. <code>myArray.length;</code></p>
<p>jQuery: <code>jQuery.grep(myArray, function(){});</code> vs. <code>myArray.grep(function(){});</code><code></code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Patrick McElhaney</title>
		<link>https://www.barneyb.com/barneyblog/2008/05/08/prototypes-array-dot-all-with-jquery/comment-page-1/#comment-87097</link>
		<dc:creator>Patrick McElhaney</dc:creator>
		<pubDate>Fri, 09 May 2008 15:23:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=391#comment-87097</guid>
		<description>I found a &lt;em&gt;slightly&lt;/em&gt; simpler way to do what you want.

All: 
&lt;code&gt;
jQuery.grep(images, function(o){return o.status == &quot;ready&quot;;}).length == images.length
&lt;/code&gt;

Any:
&lt;code&gt;
jQuery.grep(images, function(o){return o.status == &quot;ready&quot;;}).length &gt; 0
&lt;/code&gt;

Also, have you looked at the &lt;a href=&quot;http://plugins.jquery.com/project/Collection&quot; rel=&quot;nofollow&quot;&gt;Collection plugin&lt;/a&gt;? I haven&#039;t used it myself, but it might have some of the stuff you&#039;re missing.

If I were you I would try and avoid bringing stuff over directly from Prototype. It might stifle your JQuery indoctrination. :-)</description>
		<content:encoded><![CDATA[<p>I found a <em>slightly</em> simpler way to do what you want.</p>
<p>All:<br />
<code><br />
jQuery.grep(images, function(o){return o.status == "ready";}).length == images.length<br />
</code></p>
<p>Any:<br />
<code><br />
jQuery.grep(images, function(o){return o.status == "ready";}).length &gt; 0<br />
</code></p>
<p>Also, have you looked at the <a href="http://plugins.jquery.com/project/Collection" rel="nofollow">Collection plugin</a>? I haven't used it myself, but it might have some of the stuff you're missing.</p>
<p>If I were you I would try and avoid bringing stuff over directly from Prototype. It might stifle your JQuery indoctrination. :-)</p>
]]></content:encoded>
	</item>
</channel>
</rss>
