Curry

function curry(fn, ...args) {
  const length = fn.length
  let lists = args || []
  let listLen
  return function (..._args) {
    lists = [...lists, ..._args]
    listLen = lists.length
    if (listLen < length) {
      const that = lists
      lists = []
      return curry(fn, ...that)
    } else if (listLen === length) {
      const that = lists
      lists = []
      return fn.apply(this, that)
    }
  }
}
posted @ 2020-06-23 15:33  雲天望垂墨傾池  阅读(192)  评论(0编辑  收藏  举报