异步小工具 asyncTool

class asyncTool {
  constructor () {
    this.arr = []
  }

  use (func) {
    const into = {
      func,
      next: () => {}
    }
    this.arr.push(into)
    if (this.arr.length > 1) {
      const index = this.arr.length - 2
      const nextFunc = () => {
        func(this.arr[index + 1].next)
      }
      this.arr[index].next = nextFunc
    }
  }

  run () {
    if (this.arr.length > 0) {
      this.arr[0].func(this.arr[0].next)
    }
  }
}

export default asyncTool
const ac = new this.$asyncTool()
      ac.use(this.func1)
      ac.use(this.func2)
      ac.run()
原文地址:https://www.cnblogs.com/pengchenggang/p/14030013.html