How do I use requestAnimationFrame to call my js prototype?
javascript
Solution
You must think (debug) about what mean `self` on that context.
Use a local variable to bind original context:
var that = this;
window.webkitRequestAnimationFrame( function() { that.animate(); } );
Or use the `bind` function:
window.webkitRequestAnimationFrame( this.animate.bind(this) );
Problem
I want to call my methid animate indefinetely using requestAnimationFrame. However , the approach I am using does not seem to work.. Here are my codes .. ``` <html> <head> <meta charset="utf-8"> <script> function object(){ this.index = 0; } object.prototype.animate = function(){ alert("vimak"); window.webkitRequestAnimationFrame( self.animate); } me = new object(); me.animate(); </script> </head> <body> </body> </html> ``` it gives me the folowing error.. Uncaught Error: TYPE_MISMATCH_ERR: DOM Exception 17 How do I fix this ? Edited version ``` <html> <head> <meta charset="utf-8"> <script> function object(){ this.index = 0; } object.prototype.animate = function(){ var that = this;console.log(that); window.webkitRequestAnimationFrame( that.animate); } me = new object(); me.animate(); </script> </head> <body> </body> </html> ``` The output is object requestAnimationFrame.html:12 Window requestAnimationFrame.html:12 Uncaught Error: TYPE_MISMATCH_ERR: DOM Exception 17 How do I make this work ?