why I don't get the content array result 0,1,2?
<p>I have a code:
<a href="http://jsfiddle.net/centerwow/GEnPf/12/" rel="nofollow">Demo jsFiddle</a></p>

<p>which loop three times, each time creating a new function that returns the loop sequence number. </p>

<p>I expected to see the loop sequence inser to array : <strong>0, 1, and 2.</strong></p>

<pre><code>a[i] = function() {
            return i;
        }
</code></pre>

<p>everything looks normal but when I try to print the array I got </p>

<p>the resualt:</p>

<pre><code>arr[0] is =&gt;function () { return i; }
arr[1] is =&gt;function () { return i; }
arr[2] is =&gt;function () { return i; }
</code></pre>

<p>the code:</p>

<pre><code>function f() {
    var a = [];
    var i;
    for (i = 0; i &lt; 3; i++) {
        a[i] = function() {
            return i;
        }
    }
    return a;
}
var arr = f();

for (var index = 0; index &lt; arr.length; index++) {
    document.write("&lt;b&gt;arr[" + index + "] is &lt;/b&gt;=&gt;" + arr[index] + "&lt;br&gt;");
}​
</code></pre>

<p>why I don't get the resualt <strong>0, 1, and 2.</strong> ?</p>

<p>many thx.</p>
