Javascript examples for DOM:Key Event
Using requestAnimationFrame with this keyword
<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>