js 管道

function fun1(ss) {
  console.log(ss + "1")
  return 'b'
}
function fun11(ss) {
  console.log(ss + "11")
  return 'ab'
}
function fun12(ss) {
  console.log(ss + "12")
  return 'abc'
}

const funpipe = function () {
  const args = Array.from(arguments)
  //console.log(args)
  return function (val) {
    //console.log(val)
    for (let i = 0; i < args.length; i++) {
      const fun = args[i]
      val = fun(val)
    }
    return val
  }
}

funpipe(fun1, fun11, fun12)("aa")

aa1
b11
ab12

 

posted @ 2024-07-30 13:52  howhy  阅读(5)  评论(0编辑  收藏  举报