title: Doesn't JavaScript support closures with local variables?
body: <p>I am very puzzled about this code:</p>
  <pre><code>var closures = [];
  function create() {
    for (var i = 0; i &lt; 5; i++) {
      closures[i] = function() {
        alert(&quot;i = &quot; + i);
      };
    }
  }
  
  function run() {
    for (var i = 0; i &lt; 5; i++) {
      closures[i]();
    }
  }
  
  create();
  run();
  </code></pre>
  <p>From my understanding it should print <code>0,1,2,3,4</code> (isn't this the concept of closures?).</p>
  <p>Instead it prints <code>5,5,5,5,5</code>.</p>
  <p>I tried Rhino and Firefox.
  Could someone explain this behavior to me?</p>