下面的.reduce()
方法,取自this SO answer包含许多参数(显然称为解构对象)。
这些参数代表什么功能?
let {result} = array.reduce(({arg_1, arg_2, arg_3}, arg_4)=> {
}, {result: [], arg_2: 0, arg_3: undefined})
return result
最佳答案
reduce方法接受两个参数。
语法:
arr.reduce(callback[, initialValue])
因此,在您的示例中,用作第一个参数的回调是 arrow function 。让我们打破它:
1. ({arg_1, arg_2, arg_3}, arg_4)=> {} //the callback
2. {arg_1: [], arg_2: 0, arg_3: undefined} // the initial value
并且({arg_1, arg_2, arg_3}, arg_4)
有两个参数arrow function ,first 被声明为对象。
您可以注意到 arg_4
的初始值丢失了。
关于javascript - 了解 .reduce() 中的许多函数参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38845696/