Francesco Meli
Francesco Meli

Reputation: 2700

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?

Upvotes: 2

Views: 192

Answers (1)

Magus
Magus

Reputation: 15114

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

Upvotes: 8

Related Questions