Skip to content

实现函数柯里化

js
function curry(fn, args) {
  const length = fn.length;
  args = args || [];
  return function () {
    const _args = [].slice.call(arguments);
    const allArgs = args.concat(_args);
    if (allArgs.length < length) {
      return curry.call(this, fn, allArgs);
    } else {
      return fn.apply(this, allArgs);
    }
  };
}
function curry(fn, args) {
  const length = fn.length;
  args = args || [];
  return function () {
    const _args = [].slice.call(arguments);
    const allArgs = args.concat(_args);
    if (allArgs.length < length) {
      return curry.call(this, fn, allArgs);
    } else {
      return fn.apply(this, allArgs);
    }
  };
}