Using requestAnimationFrame with this keyword - Javascript DOM

Javascript examples for DOM:Key Event

Description

Using requestAnimationFrame with this keyword

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//from   w  ww .  ja  v a  2 s  .c  o  m
var Game = function () {
        this.counter = 0;
        this.loopBound = this.loop.bind(this);
        this.loopBound();
    }
    Game.prototype.loop = function () {
        console.log(this.counter++);
        requestAnimationFrame(this.loopBound);
    }
    var gameOne = new Game();
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials