Error when referencing requestanimationframe from object
-
12-06-2021 - |
题
I'm trying to call mozRequestAnimationFrame in firefox, but I keep getting an error. Here is my code:
var obj={
animFrame:mozRequestAnimationFrame
}
var animF=mozRequestAnimationFrame;
function a(){
console.log('a called');
}
animF(a);
obj.animFrame(a);
The error occurs with the obj.animFrame(a);
I get an error message of:
Illegal operation on WrappedNative prototype object
I found this thread on SO: requestAnimationFrame with this keyword and then figured that maybe requestanimationframe didn't have the right "this" context, so I tried
obj.animFrame(a).bind(window);
but still got the same error message. So why is the error occurring?
解决方案
I dont know reason why you need to save pointer to requestAnimationFrame
(mozRequestAnimationFrame
) into some object, but try next code to avoid error:
var obj={
animFrame:mozRequestAnimationFrame.bind(window)
}
function a(){
console.log('a called');
}
obj.animFrame(a);
不隶属于 StackOverflow