title: requestAnimationFrame, Non Globally?
body: <p>So I am trying to create an 'Animator' Module, that basically makes it easy to start and stop requestAnimationFrame Loops</p>
  
  <pre><code>define(function(require, exports, module) {
    var a = require( 'js/lib/stats.min.js'  );
  
    function Animator(){
  
      this.stats = new Stats();
      this.stats.domElement.style.position  = 'absolute';
      this.stats.domElement.style.bottom    = '0px';
      this.stats.domElement.style.right     = '0px';
      this.stats.domElement.style.zIndex   = '999';
  
      this.requestAnimationFrame = requestAnimationFrame;
  
      document.body.appendChild( this.stats.domElement );
  
  
    }
  
    Animator.prototype.start = function(){
      this.animate( this );
    }
  
    Animator.prototype.stop = function(){
  
      if (requestId) {
        cancelAnimationFrame(this.requestId);
        this.requestId = undefined;
      }
  
    }
  
    Animator.prototype.animate = function( ){
  
      this.update();
  
      this.requestId = this.requestAnimationFrame( this.animate );
  
   }
  
  
   // Empty function, because it will be user defined
   Animator.prototype.update = function(){
  
   }
  
    return Animator
  
  });
  </code></pre>
  
  <p>As you can tell I'm doing some illegal things here:</p>
  
  <p>First Off I am trying to assign requestAnimationFrame to this.requestAnimationFrame. This is because on the .animate function of the prototype, I want to be able to access the update function of this object. The problem is that when I do this, like so:</p>
  
  <pre><code>Animator.prototype.animate = function( ){
  
    whichAnimator.update();
  
    whichAnimator.requestId = requestAnimationFrame( whichAnimator.animate( whichAnimator ) );
  
  }
  </code></pre>
  
  <p>I get a maximum stack call exceeded. </p>
  
  <p>I guess I am wondering what the best way is to do this, because at this point I obviously have no idea what I am doing.</p>
  
  <p>If you have any questions please ask, and thanks in advance for your time!</p>