Unexpectedly passing integer by reference?
<p>I'm having some issues with this. For some reason, <code>updateCurrentItem</code> is always called with the same parameter regardless.</p>

<pre><code>function updatePromoList(query) {
    query = query.toUpperCase();
    clearCurrentList();
    var numItems = 0;
    currentItem = 0;

    result_set = cached[query.charAt(0)][query.charAt(1)][query.charAt(2)];

    for(i in result_set){
        if(numItems &gt;= NUMBER_MATCHES){
            $("&lt;li/&gt;").html("&lt;span style='color: #aaa'&gt;Please try to limit your search results&lt;/span&gt;").appendTo("#possibilities").mouseover(function(event){ updateCurrentItem(numItems+1); });
            break;
        }

        promo = result_set[i];
        found_number = false;
        if (!promo.client)
            found_number = (promo.prj_number.toString().substr(0,query.length) == query) ? true : false;

        if (query.length &gt;= MATCH_NAME) {
            if(promo.prj_name &amp;&amp; typeof promo.prj_name == 'string'){
                found_name = promo.prj_name.toUpperCase().indexOf(query);
            } else {
                found_name = -1;
            }  
            if (promo.client)
                found_client = promo.client_name.toString().indexOf(query);
            else
                found_client = -1;
        } else {
            found_name = -1;
            found_client = -1;
        }

        if(found_client &gt;= 0) {
            var thisIndex = numItems+1;
            console.log("setting", thisIndex);
            $("&lt;li/&gt;").text(promo.client_name).bind('click',function(e){ updatePromoChoice(e,promo); }).appendTo("#possibilities").mouseover(function(event){ updateCurrentItem(thisIndex); });        } else if(found_name &gt;= 0 || found_number) {            var thisIndex = numItems+1;
            console.log("setting", thisIndex);
            $("&lt;li/&gt;").text(promo.prj_number+": "+promo.prj_name).bind('click',function(e){ updatePromoChoice(e,promo); }).appendTo("#possibilities").mouseover(function(event){ updateCurrentItem(thisIndex); });
        }

        if(found_number || found_client &gt;= 0 || found_name &gt;= 0){
            numItems++;
        }
    }
}


function updateCurrentItem(i){
    currentItem = i;
    console.log("updating to", i);
}
</code></pre>

<p>The results of running this are:</p>

<pre><code>setting 0
setting 1
setting 2
setting 3
setting 4
setting 5
setting 6
setting 7
setting 8
setting 9
setting 10
setting 11
setting 12
setting 13
</code></pre>

<p>then when I move my mouse over the content area containing these <code>&lt;li&gt;</code>s with the <code>mouseOver</code> events, all I ever see is:</p>

<pre><code>updating to 4
</code></pre>

<p><em><strong>Always</em></strong> 4. Any ideas?</p>
