title: JavaScript: Pass a variable from one function to another, using setInterval()?
body: <p>So I have a function that loops executing a function, example:</p>
  
  <pre><code>function(f){
    var variable;
    for(z = 0; z &lt; 10; z++){
      variable = "cool";         
      setInterval(f)
    }
  </code></pre>
  
  <p>Btw, the real function is MUCH more complex than this but it's the same theory.
  I want to be able to execute the function in argument <em>f</em> and set some variables (ex. <em>variable</em>) so that this function can use them, in a whole this is the idea:</p>
  
  <pre><code>function say(f){
     var variable = "hey";
     setInterval(f);
  }
  say(function(){
     alert(variable)
  });
  </code></pre>
  
  <p>Here, one should get an alert box saying <em>hey</em>. That's the theory, but it wont work:</p>
  
  <blockquote>
    <p>Variable "variable" isn't defined</p>
  </blockquote>
  
  <p>The browser will probably just ignore the error and alert <em>undefined</em>.</p>
  
  <p>But anyways, how do I "pass" the variable <strong>without changing the scope of it</strong>.</p>