其本质是,将一个多参数的一个函数,分解为一系列单参数(部分参数)的函数的过程,仅有参数完全传递完毕再去执行

// 柯里化函数实现(最小可行模型)
function curry(fn) {
    return function curried(...args) {
        if (args.length >= fn.length) {
            return fn.apply(this, args);
        } else {
            return function(...args2) {
                return curried.apply(this, args.concat(args2));
            }
        }
    }
}
 
// 原函数:制作火锅
const makeHotpot = (base, flavor, food) => `锅底:${base}, 口味:${flavor}, 食材:${food}`;
 
const curriedMake = curry(makeHotpot);
const basePot = curriedMake("水+油"); // 固定基础配方
const spicyPot = basePot("麻辣");     // 固定口味
console.log(spicyPot("毛肚"));        // 最终产出