在一个项目中,我有这样的BabelJS配置:
{
"presets": ["es2016"]
}在代码中的某个地方,有一种方法使用标准的JS‘参数’关键字来处理参数的动态范围。就像这样:
const myFunction = () => {
// pass all arguments with spread operator
someOtherFunction(...arguments);
}
myFunction('one', 'two', 3, {number: 4});到目前为止还不错,但是当BabelJS完成时,它已经(1)将‘参数’定义为一个全局变量,(2)在某种程度上它本身也必然失败:
var arguments = arguments;有办法阻止BabelJS这样做吗?或者通过配置或者一些特殊的注释来做例外?
发布于 2018-02-01 10:15:12
不要使用神奇的arguments变量。
(...args) => {
// pass all arguments
someOtherFunction(...args);
}如果您出于某种原因必须使用arguments变量(提示,您几乎总是不使用),那么您必须像使用.apply()之前一样使用ES5。
(function() {
someOtherFunction.apply(null, arguments);
})https://stackoverflow.com/questions/48560169
复制相似问题