自己实现的简陋的promise
2018-04-06 本文已影响0人
李永州的FE
没有状态
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函数里面的')
})