Javascript function Arguments对象神奇的变成了当前的webpack模块?
Javascript function Arguments object becomes the current webpack module magically?
我正在使用 Redux 和 mapDispatchToProps
函数构建一个 React 应用程序 - 我正在使用下面的模式。
const mapDispatchToProps = (dispatch) => {
debugger
Object.keys(actions).forEach(key => {
var functionObj = actions[key];
actions[key] = () => {
debugger
var zz = Array.prototype.slice.call(arguments);
dispatch(functionObj.apply(null,zz));
}
});
return actions;
}
让我发疯的是参数对象是我所期望的(带有参数 bla bla 的类似对象的数组),除非我以任何方式 "use" 它。 "use" 我的意思是:
将其分配给某些东西(如上面的 var zz
)或将其传递给函数。当我 "use" arguments 对象时 - 它神奇地变成了我当前所在的当前 Webpack 模块。
有人知道这件事吗?我疯了吗??
这是由于箭头函数 do not provide an arguments
object. So you are referencing the module wrapper function 是最近的 non-arrow 函数造成的。
你可以用rest parameters instead. Good riddence! Rest parameters are a true array and do not need to be converted with any Array#slice()废话来解决这个问题。
下面是一个示例,我也使用了 spread operator to avoid the need to use Function#apply(),因为您似乎不需要任何特殊的 this
值。
const mapDispatchToProps = (dispatch) => {
debugger
Object.keys(actions).forEach(key => {
var functionObj = actions[key];
actions[key] = (...zz) => {
debugger
dispatch(functionObj(...zz));
}
});
return actions;
}
我正在使用 Redux 和 mapDispatchToProps
函数构建一个 React 应用程序 - 我正在使用下面的模式。
const mapDispatchToProps = (dispatch) => {
debugger
Object.keys(actions).forEach(key => {
var functionObj = actions[key];
actions[key] = () => {
debugger
var zz = Array.prototype.slice.call(arguments);
dispatch(functionObj.apply(null,zz));
}
});
return actions;
}
让我发疯的是参数对象是我所期望的(带有参数 bla bla 的类似对象的数组),除非我以任何方式 "use" 它。 "use" 我的意思是:
将其分配给某些东西(如上面的 var zz
)或将其传递给函数。当我 "use" arguments 对象时 - 它神奇地变成了我当前所在的当前 Webpack 模块。
有人知道这件事吗?我疯了吗??
这是由于箭头函数 do not provide an arguments
object. So you are referencing the module wrapper function 是最近的 non-arrow 函数造成的。
你可以用rest parameters instead. Good riddence! Rest parameters are a true array and do not need to be converted with any Array#slice()废话来解决这个问题。
下面是一个示例,我也使用了 spread operator to avoid the need to use Function#apply(),因为您似乎不需要任何特殊的 this
值。
const mapDispatchToProps = (dispatch) => {
debugger
Object.keys(actions).forEach(key => {
var functionObj = actions[key];
actions[key] = (...zz) => {
debugger
dispatch(functionObj(...zz));
}
});
return actions;
}