Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>jQuery objects are array-like, so look and behave a lot like arrays, but are in fact just custom objects made to roughly equate to a collection of DOM nodes (except with added functionality). All the array-like functionality - length, slice() etc.. - is in fact added manually to the jQuery prototype (for which <code>jQuery.fn</code> is an alias), sometimes by calling an array function with the jQuery object as context </p> <pre><code> slice = Array.prototype.slice, ... slice: function() { return this.pushStack( slice.apply( this, arguments ), "slice", slice.call(arguments).join(",") ); }, </code></pre> <p>and sometimes by writing it from scratch. Look at the <a href="http://robflaherty.github.com/jquery-annotated-source/docs/01-core.html" rel="nofollow noreferrer">annotated code</a> (probably a very useful resource for you - it covers v1.6.2 but I don't think anything too drastic has changed since then, except maybe the addition of $.callbacks) to see that <code>this.length</code> is set manually e.g.</p> <pre><code>if ( selector === "body" &amp;&amp; !context &amp;&amp; document.body ) { this.context = document; this[0] = document.body; this.selector = selector; this.length = 1; return this; } </code></pre> <p>the <code>jQuery.buildFragment()</code> method is also fundamental to how jQuery objects containing larger collections of DOM nodes are constructed.</p> <p>So to sum up, jQuery doesn't use arrays, it just looks like it does because much native array functionality has been replicated as properties of the jQuery prototype.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload