美文网首页
自己实现的简陋的promise

自己实现的简陋的promise

作者: 李永州的FE | 来源:发表于2018-04-06 16:45 被阅读0次

没有状态

function  fakepromise(fn) {
      var that = this
      function f1() {
          that.arr[0]()
      }
      fn(f1)
      this.arr = []
      this.then = function (fn) {
          this.arr.push(fn)
      }
  }
   var p = new fakepromise(function (resolve,reject) {
       setTimeout(function () {
           console.log('hhh')
           resolve()
       }, 0)
   })
    p.then(function () {
        console.log('我是then函数里面的')
    })

相关文章

网友评论

      本文标题:自己实现的简陋的promise

      本文链接:https://www.haomeiwen.com/subject/xfgftftx.html