title: How to call an anonymous function from setTimeout
body: <p>I have a loop, a setTimout and a callback. I need to use an anonymous function to keep the variables correct in the callback.</p>
  
  <p>I want to have the callback as a separate function because it is too large to have in the loop.</p>
  
  <p>This does not work:</p>
  
  <pre><code>for (var i = 0; i &lt; 10; i++) {
    setTimeout(callback, 1000*i, i);
  }
  
  var callback;
  (callback = function(i) {
    console.log(i);
  })();
  </code></pre>
  
  <p>How can define an anonymous function that I can call from setTimeout?</p>