Variables in a setTimeout inside a loop (scope issue)
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/750486/javascript-closure-inside-loops-simple-practical-example">Javascript closure inside loops - simple practical example</a><br>
  <a href="http://stackoverflow.com/questions/5986588/calling-settimeout-function-within-a-loop">Calling setTimeout function within a loop</a>  </p>
</blockquote>



<p>before calling this a duplicate, I looked on the internet and everyone seemed to have different problems. If anybody could help me with this particular one, it'd be greatly appreciated.</p>

<p>Basicaly, what I have is two <code>for</code> loops nested inside a 3rd one.</p>

<pre><code>for (a=0 ... a++) {
    for (b=0 ... b++) {
        setTimeout( ... + a + ..., 1000*b);
    }
    for (c=0 ... c++) {
        setTimeout( ... + a + ..., 1000*c);
    }
}
</code></pre>

<p>This is some pseudo code just to avoid the junk, but basically I want to pass the <code>a</code> value to the callback function triggered by the timer. The problem comes from the fact <code>a</code> is being incremented, so when then event is fired, the function has the last value of <code>a</code> instead of the one one it one registered.</p>

<p>I can think of it like a reference or a pointer in C/C++, this is really annoying. Any way to give it a permanent value?</p>
