title: javascript closure on function objects
body: <p>Why does closure behavior not come into play here:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function init(){
    for (var i = 1; i &lt;= 2; i++) {
    
    function timer() {
      var k=i;
      console.log("in timer");
      console.log(timer.i);
      console.log(k);
    }
    
    timer.i = i;
    setTimeout(timer, 0);
    
    }
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;body onload="init()";&gt;
  &lt;/body&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Why does timer.i not take the last value of i on the outer function init's stack? However, it does take the outer for k.</p>