title: How can I create multiple setInterval()s dynamically?
body: <p>I have a script that needs a function to be run multiple times per object, but the number of objects is set in a variable by the user.</p>
  
  <p>It would work like this</p>
  
  <pre><code>dothis(1);
  dothis(2);
  dothis(3);
  </code></pre>
  
  <p>However this doesn't work</p>
  
  <pre><code>for (var i = 0; i &lt; howMany; i++)
  {
      setInterval(
          function()
          {
              dothis(i);
          },
          (Math.floor(Math.random() * 10) + 1)
      );
  }
  </code></pre>