Creating closures in a loop in JavaScript
<p>I have this scenario:</p>

<pre><code>&lt;html&gt;
&lt;head&gt;
&lt;script type="text/javascript" src="jquery-1.4.4.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;
var actions = {
    'view' : function(){alert("view");},
    'history': function(){alert("history");},
    'renewal': function(){alert("renewal");}
}
for(var action in actions){
    $('.' + action).live('click', function(e){
        e.preventDefault();
        if(actions[action])
            actions[action]();
    });
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;a class="view" href="#"&gt;view&lt;/a&gt;
    &lt;a class="history" href="#"&gt;history&lt;/a&gt;
    &lt;a class="renewal" href="#"&gt;renewal&lt;/a&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>I think a closure is created, since clicking a link always alerts "renewal" and I am not able to fix it.</p>
