Currying-in function and ES6 destructing

191 views Asked by At

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?

1

There are 1 answers

1
Magus On BEST ANSWER

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