简体   繁体   中英

Currying-in function and ES6 destructing

I was testing some currying-in function and I could get this to work pretty easily:

test = (a) => { return (b) => a+b } // test(5)(6) => 11

I couldn't get to work the same function when using the ES6 destructing argument:

test = ({a}) => { return (b) => a+b } // test(5)(6) => NaN 

Is there a way to have it work? Why doesn't the second test function work?

If you use a destructuring argument, you have to call your function with an object :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM