通用珂理化、反珂理化方法

2019-07-24  本文已影响0人  TerdShow
function curry(fn, ...restArgs){
  let _restArgs = restArgs || [];
  let len = fn.length;
  let _this = this;
  return function(){
    let newArgs = [..._restArgs, ...Array.from(arguments)];
    if(newArgs.length < len){
      return curry.call(_this, fn, newArgs);
    }else{
      return fn.apply(this, newArgs);
    }
  }
}

function unCurry(fn) {
  return function(...args){
    args.forEach(item => {
      if(typeof item !== 'function'){
        return;
      }else{
        fn = fn(item);
      }
      return fn;
    })
  }
}
上一篇 下一篇

猜你喜欢

热点阅读