monic-shixi / blog

以babel开始,记录一些技术问题到issue里
2 stars 0 forks source link

使用柯里化的例子 #7

Open monic-shixi opened 5 years ago

monic-shixi commented 5 years ago
add = (arr) => arr.reduce((sum, value) => sum+=value, 0)
function curryFactory(fn, length){
  return fner = (...args) => args.length === length ? fn(args) : fner.bind(null, ...args)
}
curry = curryFactory(add, 5)
curry(2)(2)(2)

这就是一个简单的柯里化