Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const mul = (a, b = 2) => a * b;
- const badlyCurriedMul = curry(mul);
- badlyCurriedMul(1) // 2, the curried function will use the default parameter immediately.
- // And that's because mul.length is 1.
- console.log(mul.length); // 1
- // That's right, function length will not take default parameter into account
- // so we need to specify the correct length
- const curriedMul = curry(mul, 2);
- curriedMul(1); // fn ...
- curriedMul(1, 5); // 5
- // and now it work
Add Comment
Please, Sign In to add comment