concept

When a function has multiple arguments, it is called by passing some of the arguments (the arguments never change), and then returns a new function that takes the rest of the arguments and returns the result.

Currization is a technique for converting a function that takes multiple arguments into a series of functions that take one argument.

Function checkAge(min, age) {return age >= min} console.log(checkAge(18, Function checkAge (min) {return function (age) {return age >= min}} (age => age >= min) console.log(checkAge(18)(24))Copy the code

Simulation of the Currization principle

function curry (func) { return function curriedFn(... If (args. Length < func.length) {return function () {return curriedFn(... args.concat(Array.from(arguments))) } } return func(... args) } }Copy the code

advantages

Reduces code redundancy and increases readability

conclusion

  • Corrification allows us to pass in fewer arguments to a function and get a new function that has memorized some of the fixed arguments
  • This is a cache of function parameters
  • Make the function more flexible, make the function smaller granularity
  • Multiple functions can be converted into one variable functions, and functions can be combined to produce powerful functions