函数柯里化

74 阅读1分钟

概念:柯里化过程:接受A函数作为参数,然后返回一个新函数,这个新函数可以逐步处理函数A的参数。 新函数就是柯里化函数

function curry(fn) {
        const result = []
        return function Fn(...args) {
          result.push(...args)
          if (result.length === fn.length) {
            return fn.call(this, ...result)
          } else {
            return Fn
          }
        }
      }
function A(x, y) {
        console.log(x, y, this)
        return x + y
      }
      console.log(curry(A)(1)(3))