title: Adding new function objects to array and then calling function method
body: <p>I am not sure if I used the correct terminology exactly in the question but I am triggering a series of timed function calls using a loop in my playSequence() function and the setTimeOutFunction.  This much works, but then I want to have a pause function that will pause all timers and a resume function that will resume all timers.  The problem is that when I try to call the function object's pause method in the pauseAllTimers() function it gives error 'Uncaught TypeError: Object 0 has no method 'pause'.  Any ideas?  </p>
  
  <pre><code>var timers = new Array();
  
  function Timer(callback, delay) {
  var timerId, start, remaining = delay;
  
  this.pause = function() {
      window.clearTimeout(timerId);
      remaining -= new Date() - start;
  };
  
  this.resume = function() {
      start = new Date();
      timerId = window.setTimeout(callback, remaining);
  };
  
  this.resume();
  }
  
  function pauseAllTimers()
  {
  for (var timer in timers) 
  {   
      timer.pause();
  }
  } 
  
  function resumeAllTimers()
  {
  for (var timer in timers) 
  {   
      timer.resume();
  }
  }
  
  function playSequence()
  {
  var totaltimeout = 0;
  for (var lesson_step_str in lesson_step) 
  {
      var splitarr = lesson_step[lesson_step_str].split("|||");
      var element = splitarr[0];
      var txt = splitarr[1];
      var timeout = splitarr[2];
      totaltimeout += (timeout*1);
      console.log(totaltimeout);
      console.log(txt);
  
      (function(a,b){
  
       var timer = new Timer(function(){ displayText( a, b); }, totaltimeout * 1000);
       timers.push(timer);
    })(element, txt);
  
  }   
  }
  </code></pre>