concept
The technique of converting a function that takes multiple arguments into a function that takes a single argument (the first argument of the original function) and returns a new function that takes the remaining arguments and returns the result
The paper
A function that prefills several arguments returns another function that merges its arguments with the prefilled arguments and executes the function logic
The Kerrization of JS
Separate the parameters that a function receives into fixed functions, and return the received values
Common function
function fn(a, b, c) {
console.log(a + b + c);
}
fn(3.4.5);
Copy the code
After the curry
function kl(a) {
return function(b) {
return function(c) {
console.log(a + b + c);
};
};
}
kl(3) (4) (5);
Copy the code
Analysis of the
So each of these functions is going to take in one value and return the result, let me write it another way.
advantages
- Single entry, easy to test and reuse
- Easy to troubleshoot
disadvantages
- Nested function
- memory
- Low efficiency
challenge
In actual scenarios, how to correctly use Coriolization based on different business requirements?