title: JavaScript setTimeout setInterval within one function
body: <p>I think I might be overtired but I cannot for the life of me make sense of this, and I think it's due to a lack of knowledge of javascript</p>
  <pre><code>var itv=function(){
   return setInterval(function(){
    sys.puts('interval');
   }, 1000);
  }
  var tout=function(itv){
   return setTimeout(function(){
    sys.puts('timeout');
    clearInterval(itv);
   }, 5500);
  }
  </code></pre>
  <p>With these two functions I can call</p>
  <pre><code>a=tout(itv());
  </code></pre>
  <p>and get a looping timer to run for 5.5 seconds and then exit, essentially.</p>
  <br>
  <hr />
  <p>By my logic, this should work but it simply is not</p>
  <pre><code>var dotime=function(){
   return setTimeout(function(){
    clearInterval(function(){
     return setInterval(function(){
      sys.puts(&quot;interval&quot;);
     }, 1000);
    });
   }, 5500);
  }
  </code></pre>
  <p>any insight in this matter would be appreciated.</p>