How do you handle multiple instances of setTimeout()?
<p>What is the most recommended/best way to stop multiple instances of a setTimeout function from being created (in javascript)?</p>

<p>An example (psuedo code):</p>

<pre><code>function mouseClick()
{
   moveDiv("div_0001", mouseX, mouseY);
}

function moveDiv(objID, destX, destY)
{
   //some code that moves the div closer to destination
   ...
   ...
   ...

   setTimeout("moveDiv(objID, destX, destY)", 1000);
   ...
   ...
   ...
}
</code></pre>

<p>My issue is that if the user clicks the mouse multiple times, I have multiple instances of moveDiv() getting called.</p>

<p>The option I have seen is to create a flag, that only allows the timeout to be called if no other instance is available...is that the best way to go?</p>

<p>I hope that makes it clear....</p>
