How does jQuery make the returned value look like an array?
<pre><code>jQuery(); //[]
jQuery("#footer"); //[&lt;div id="footer"&gt;...&lt;/div&gt;]
</code></pre>

<p>I know that you can do something like this:</p>

<pre><code>function kablam(tag) {
    var els = document.getElementsByTagName(tag);
    els.isKablam = true;
    return els;
}
var body = kablam("body"); //[&lt;body class="ask-page"&gt;...&lt;/body&gt;]
body.isKablam; //true
</code></pre>

<p>To return an "extended" version of the <a href="http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-1938918D"><code>NodeList</code></a> that's returned from <code>document.getElementsByTagName</code>.</p>

<p>However, jQuery does the opposite. It merges the result into itself (as can be seen <a href="https://github.com/jquery/jquery/blob/master/src/core.js#L142">here</a> and <a href="https://github.com/jquery/jquery/blob/master/src/core.js#L188">here</a>). Furthermore, that doesn't explain how it returns an array-like-object-that-looks-like-an-array when you pass nothing to it:</p>

<pre><code>jQuery(); //[]
</code></pre>

<p>When you do that, jQuery simply returns itself. (<a href="https://github.com/jquery/jquery/blob/master/src/core.js#L84">source</a>)</p>

<p>Or to the same extend, when you select the body tag:</p>

<pre><code>jQuery("body"); //[&lt;body class="ask-page"&gt;...&lt;/body&gt;]
</code></pre>

<p>(<a href="https://github.com/jquery/jquery/blob/master/src/core.js#L96">source</a>)</p>

<p>Or, come to think of it, anything at all:</p>

<pre><code>var o = {}, body = document.getElementsByTagName("body");
jQuery.merge(o, body); //Object, not [...]
</code></pre>

<p>Returning array-like objects is super easy, since assigning numeric keys is trivial and no different than assigning any other key. But how does jQuery make it "look like" an array?</p>
