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 @   雲天望垂墨傾池  阅读(193)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示