Costs of expanding an associative array in Javascript?
<p>Because finding a node with JQuery has a significant cost, I built a very simple function</p>

<pre><code>window.selectorToObject = {}

function get(selector){
    if(typeof selector === "undefined") 
      return null;
    if(selector in window.selectorToObject) 
      return window.selectorToObject[selector];
    window.selectorToObject[selector] = $(selector);
    return $(selector);
}
</code></pre>

<p>So then instead of doing <code>$(selector)</code> we will simply to <code>get(selector)</code>.</p>

<p>After a simple test, the differences are significant:</p>

<pre><code>&lt;div id="test"&gt;
  &lt;div id="child1"&gt;
    &lt;div id="child2"&gt;
       &lt;div id="child3"&gt;&lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;
</code></pre>

<p><img src="http://i.stack.imgur.com/GMlEU.png" alt="enter image description here"></p>

<p>Now I am just worry about the size of the associative array that will grow at each new <code>get()</code>.</p>

<p>Is there any costs of expanding a size of an associative array in Javascript?</p>
