title: Make a function wait for another variable
body: <p>I've gone into a project lately that requires two different methods for two different variable, but I need to store both of these values in order to use them in another function.</p>
  
  <p>It's a bit complicated, so let me explain. I've got this switch statement that watches for several numbers: 2,3,13,45</p>
  
  <pre><code>var hello;
  switch ($variable) {
      case 2:
          //do something irrelevant
          break;
      case 3:
          //do something irrelevant
          break;
      case 13:
          //do something with variable named "hello". Ex.:
          alert(hello);
          break;
      case 45:
          hello = "hello";
          break;
  }
  </code></pre>
  
  <p>As you can see, I need to get the value of "hello", before the variable gets a value. I can't change the order, nor I can't change variable declaration, so I have to do something with this setup.</p>
  
  <p>What I thought was to make a function call in 13:</p>
  
  <pre><code>function getMyVariable(variable) {
      var v = variable;
      return variable;
  }
  
  case 13:
      getMyVariable(hello);
      break;
  </code></pre>
  
  <p>Then of course the function would still return undefined. </p>
  
  <p>What I'd like to do, is to make the function wait for the variable set in 45:</p>
  
  <p>(note that this is just speculation, this code is no way near working)</p>
  
  <pre><code>case 45:
      hello = "hello";
      getMyVariable(hello);
      break;
  
  function getMyVariable(variable) {
      //function gets call from case 13
      //if type is undefined, wait for a variable that isn't undefined
      //if variable isn't undefined return the variable
  }
  </code></pre>
  
  <p>So basically at first call skip case 13, let case 45 set the variable, then go back to case 13 and execute the code here.
  Can you follow me? Tell me if you need more info!</p>