requestAnimationFrame with this keyword

后端 未结 7 843
感动是毒
感动是毒 2020-11-27 15:40

I\'m using webkitRequestAnimationFrame but I\'m having trouble using it inside of an object. If I pass the this keyword it will use window

7条回答
  •  日久生厌
    2020-11-27 16:06

    Beside bind method, and arrow function solution (offered by Jamaes World's answer), Another (rather old) work around could be:

    var self = this
    window.webkitRequestAnimationFrame(
        function() {
            self.draw()
        }
    );
    

提交回复
热议问题