ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
```js const curry = (fn, arity = fn.length, ...args)  => arity <= args.length ? fn(...args) : curry.bind(null, fn, arity, ...args); ``` ```js curry(Math.pow)(2)(10); // 1024 curry(Math.min, 3)(10)(50)(2); // 2 ``` ```js // @param {Function} fn 待柯里化的函数 // @param {array} args 已经接收的参数列表 const currying = function(fn, ...args) { const len = fn.length // fn需要的参数个数 return function (...params) { // 返回一个函数接收剩余参数 let _args = [...args, ...params] // 拼接已经接收和新接收的参数列表 // 如果已经接收的参数个数还不够,继续返回一个新函数接收剩余参数 if (_args.length < len) { return currying.call(this, fn, ..._args) } return fn.apply(this, _args) // 参数全部接收完调用原函数 } } ```