title: starting & stopping timers: using 1 function for multiple instances
body: <p>This is code used within nodered.<br>
  I'm invoking several timers with the same function, then either the timer actually runs and displays something,
  or I stop the timer (clearTimeout) and the something doens't get displayed.</p>
  
  <p>The first thing I tried is this:</p>
  
  <pre><code>// multiple calls method 1 - DOES NOT WORK (multiple calls of procedure with same name - no method to distuinguish
  function displaysomethingelse7 (rdelay7, var37, var47) {
      function performactualstuff (var3a7, var4a7) {
          node.warn ("37:"+var3a7+", 47:"+var4a7);
      }
      timer7=setTimeout(performactualstuff, rdelay7, var37, var47);
      node.warn ("starting timer27_inprocedure: "+timer7._idleStart);
      function stop7() {
          if (timer7) {
              clearTimeout(timer7);
              node.warn ("stopping timerid27 "+timer7._idleStart);
              timer7 = 0;
          }
      }
      return stop7;
  }
  // start 1
  delay20=8500;
  var20a=2;
  var20b="b";
  var t10 = displaysomethingelse7 (delay20, var20a, var20b);
  // start 2
  delay21=10500;
  var21a=3;
  var21b="c";
  var t11 = displaysomethingelse7 (delay21, var21a, var21b);
  // stop 1 ?
  stopdelay30=8000;
  setTimeout(t10, stopdelay30);
  // stop 2 ?
  stopdelay31=9000;
  setTimeout(t11, stopdelay31);
  </code></pre>
  
  <p>This doens't work since the 'stop7' function has no method to disguinguish between timerIDs.
  So I came up with an array of functions:</p>
  
  <pre><code>// multiple calls method 2 - array of functions
  function displaysomethingelsetoo (r2delay, var77, var88) {
      function performactualstufftoo (var77a, var88a) {
          node.warn ("77:"+var77a+", 88:"+var88a);
      }
      timer8=setTimeout(performactualstufftoo, r2delay, var77, var88);
      node.warn ("starting timer77_inprocedure= "+timer8._idleStart);
      if (typeof stopa  === 'undefined') stopa=[];
      stopa[timer8._idleStart] = function (tf) {
          if (tf) {
              clearTimeout(tf);
              node.warn ("stopping timerid3 "+tf._idleStart+"originaltimer="+timer8._idleStart);
              tf = 0;
          }
      }
      return stopa[timer8._idleStart];
  }
  // start 1
  delay3=4000;
  var5a=4;
  var6a="d";
  var t3a = displaysomethingelsetoo (delay3, var5a, var6a);
  // start 2
  delay4=5000;
  var5b=5;
  var6b="e";
  var t3b = displaysomethingelsetoo (delay4, var5b, var6b);
  // stop 1 ?
  stopdelay3=2000;
  setTimeout(t3a, stopdelay3, t3a);
  // stop 2 ?
  stopdelay4=3000;
  setTimeout(t3b, stopdelay4, t3b);
  </code></pre>
  
  <p>But this isn't quite correct yet either - the stopa array has all the same function in it.
  I think the solution could be to pass the parsed timer8 variable to the stopa[timer8._idleStart] function,
  but I have no idea how to to do this.</p>