箭头函数可以包含宿主函数的多个参数,例如reduce吗?

Wil*_*iam 3 javascript ecmascript-6

我认为这个问题的答案是否定的,但我不确定.下面是一个reduce函数,一个不使用箭头函数,一个是.是否可以将第一个参数合并到箭头样式中?

var s = arr.reduce(function(){

},0) // includes second argument
Run Code Online (Sandbox Code Playgroud)

和........

var a = arr.reduce = () => {

} // ?
Run Code Online (Sandbox Code Playgroud)

Tus*_*har 6

是的,箭头函数可以使用多个参数,它们只需要在括号内添加.

var s = arr.reduce((accum, currVal) => accum + currVal, 0);
                   ^              ^                       : Multiple arguments to the Arrow function
                                                       ^^^: Second argument of the `reduce` function
Run Code Online (Sandbox Code Playgroud)

这里,Array#reduce可以正常传递第二个参数.箭头函数(第一个参数)对第二个参数的传递方式没有影响.