卷入功能和ES6破坏

Fra*_*eli 2 javascript currying destructuring

我正在测试一些currying-in功能,我可以很容易地让它工作:

test = (a) => { return (b) => a+b } // test(5)(6) => 11
Run Code Online (Sandbox Code Playgroud)

使用ES6 destructing参数时,我无法使用相同的功能:

test = ({a}) => { return (b) => a+b } // test(5)(6) => NaN 
Run Code Online (Sandbox Code Playgroud)

有没有办法让它发挥作用?为什么第二个测试功能不起作用?

Mag*_*gus 8

如果使用解构参数,则必须使用对象调用函数:

test = ({a}) => { return (b) => a+b }
console.log(test({a : 5})(6)); // => 11
Run Code Online (Sandbox Code Playgroud)