title: setTimeout in for-loop does not print consecutive values
body: <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 <code>3</code> is alerted both times, instead of <code>1</code> then <code>2</code>.</p>
  
  <p>Is there a way to pass <code>i</code>, without writing the function as a string?</p>