Skip to content
On this page

函数的柯里化

函数的柯里化(把一个函数拆分成多个“小”的函数,每一个函数的参数只能有一个)

顺便注意一下偏函数概念:偏函数 (参数可以不是一个的柯理化函数)

正常来编写代码的时候,我们把偏函数也称之为柯理化

js
function curry(func) { // 柯理化函数一定是高阶函数
    const curried = (...args) => { // 用户本次执行的时候传递的参数
        if (args.length < func.length) {
            return (...others) => curried(...args,...others)
        } else {
            return func(...args)
        }
    }
    return curried
}

Released under the MIT License.