title: Closure for setInterval function in javascript
body: <p>How to use <code>setInterval</code> without using global variables? I'd prefer to wrap all variables of function invoked by setInerval in some kind of closure, like so:</p>
  
  <pre><code>var wrap = function (f){
   var local1, local2, ...;
   return function () { return f(); }
  }
  </code></pre>
  
  <p>This doesn't work, but the idea is that I'd pass <code>wrap(f)</code> instead of <code>f</code> to <code>setInterval</code>, so that locals for <code>f</code> are nicely wrapped and don't pollute the global scope.</p>