This is a tough for myself since I'm still learning as I go but what I can recollect from what I read. it restructures a function so it takes one argument, then returns another function that takes the next argument, and so on.
Here's an example:
function add(x) {
return function(y) {
return function(z) {
return x + y + z;
}
}
}
console.log(add(10)(20)(30));
- The
add(10)(20)(30)
should return60
. - This is useful in your program if you can't supply all the arguments to a function at one time. You can save each function call into a variable, that hold's the returned function that takes the next argument when it's available.
Top comments (0)