Store setTimeout and call it later
<p>Look at the following code:</p>

<pre><code>var timer=setTimeout(function(){increase();}, 8);
</code></pre>

<p>This setTimeout function will be executed immediately, but I want 
it to execute later. Why? </p>

<p>Example:</p>

<pre><code>function increase(i)
                 {
                  i++; if(i==100) return;
                  var timer=setTimeout(function(){increase(i);}, 8);
                  }
</code></pre>

<p>Now, I need to stop and exit this function within another function when certain thing happen:</p>

<pre><code>if (a==b) clearTimeout(timer);
</code></pre>

<p>The thing that bothers me is that variable timer is getting assigned, whenever 
function increase runs, but it does not need to, and I believe it is bad practice. That is why I need to assign to it only once, before function run and execute it later when need arrives. </p>

<p>I hope you understood, and btw, those are just examples, not my code.  </p>