这样做很好:
var requestAnimationFrame =
window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame;
function _test() {
console.log('hello from test');
}
requestAnimationFrame(_test);
但是,将其移动到另一个文件并使用 CommonJS/webpack 将其导出会导致:
Uncaught TypeError: Illegal invocation
(像这样:)
module.exports.requestAnimationFrame =
window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame;
...
var poly = require('../utils/polyfills');
poly.requestAnimationFrame(_test);
这可能非常明显,但在我看来,我不明白为什么这不起作用:/