setTimeout in a for-loop and pass i as value
<p>I have this script:</p>

<pre><code>for(var i=1; i&lt;=2; i++){
    setTimeout(function() { alert(i) }, 100);
}
</code></pre>

<p>But the alert message is just <strong>two times '3'</strong> (i seems to be a reference). <strong>I want the alert to be 1 and 2...</strong></p>

<p>Is there a way to pass the i, without writing the function as a string?</p>
