如果某个函数被传递到requestAnimationFrame(),该函数如何检测到它正在动画帧内被调用?
铁
function someFunction() {
if (/* What goes here? */) {
console.log('Inside animation frame.')
}
else {
console.log('Not inside animation frame.')
}
}
// The following lines should not be modified for the answer.
someFunction() // logs "Not inside animation frame."
requestAnimationFrame(someFunction) // eventually logs "Inside animation frame."
Run Code Online (Sandbox Code Playgroud)
最后两行不应修改。我很想知道是否可以检测到这种情况,而不需要用户记住以两种不同的方式使用该功能。最终用户应该像平常一样使用该函数,而不知道我的函数检测到用例。