0

I am using requestanimationframe function of javascript and also i created a object in javascript. I want to use method of my object within requestanimationframe function as callback.

syntex : requestanimationframe(callback);

And I try : requestanimationframe(this.rander); not working.

manan
  • 234
  • 2
  • 9

2 Answers2

2

You'll have to call it from another function, and use a temporary variable to get the reference to this :

var self = this;
requestAnimationFrame(function() {
    self.rander();
});
Sebastien C.
  • 4,649
  • 1
  • 21
  • 32
0
  1. Try requestAnimationFrame(); case matters in javascript
  2. Also make sure this function is supported in your browser : requestAnimaitonFrame = requestAnimationFrame || webkitRequestAnimaitonFrame || mozRequestAnimationFrame || msRequestAnimationFrame;
Vlas Bashynskyi
  • 1,886
  • 2
  • 16
  • 25
  • I am using requestAnimationFrame() in my code as well but not working. so it may not be issue of case matters.And Aslo i use latest mozilla firefox. it is working when i pass non object function in requestAnimationFrame() – manan Jul 03 '14 at 10:09
  • @VLAS Funny how you give him crap about case but then mess up the name of your impromptu-shim 'requestAnimaitonFrame' ??? – Red15 Mar 21 '16 at 11:29