title: Javascript timer delay
body: <p>I've decided to play around with HTML5's canvas, and of course that means I'm going to try writing a pong game. At the moment, I am trying to figure out how to cap my framerate. This is fairly easy in other languages, but finding a way to delay execution in Javascript seems to be a bit tougher.</p>
  
  <p>Here is what I have so far:</p>
  
  <pre><code>while(true) {
      var begin = (new Date()).getTime();
  
      //Draw stuff to the canvas
  
      var end = (new Date()).getTime();
      if ((end-begin) &lt; 33.333 ) {
          //delay (1000/(30-(end-begin)))
      }
  }
  </code></pre>
  
  <p>Obviously, frame rates will be wildly different due to how each javascript engine performs, but I want to cap the maximum framerate at 30FPS. I don't really see how setTimeout() would accomplish this task. What would be the best way to do this?</p>