首页 > 其他分享 >js柯里化

js柯里化

时间:2022-10-17 16:56:50浏览次数:48  
标签:function return log args js 柯里化 sc console

function sum(a, b, c) {
  return a + b + c
}

function curry(f) {
  return function fn(...args) {
    if (args.length >= f.length) {
      return f.apply(this, args)
    } else {
      return function (...args2) {
        return fn.apply(this, args.concat(args2))
      }
    }
  }
}

const sc = curry(sum)
console.log(sc(1, 2, 3))
console.log(sc(1)(2, 3))
console.log(sc(1, 2)(3))

标签:function,return,log,args,js,柯里化,sc,console
From: https://www.cnblogs.com/samsara-yx/p/16799770.html

相关文章