【发布时间】:2015-02-14 14:49:07
【问题描述】:
这样做效果很好:
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);
这可能非常明显,但在我看来,我不明白为什么这不起作用:/
【问题讨论】:
标签: javascript commonjs webpack method-invocation