js的柯里化

//作用:1.函数参数复用
//2.兼容性的检测
//3.延迟执行

function add() {
    
    
  let args = Array.prototype.slice.call(arguments);
  let inner = function () {
    
    
    args.push(...arguments);
    return inner;
  };
  inner.toString = function () {
    
    
    return args.reduce(function (pre, after) {
    
    
      return pre + after;
    });
  };
  return inner;
}

Guess you like

Origin blog.csdn.net/weixin_43595755/article/details/118278667