class MPromise {
constructor(handle) {
this._status = PENDDING
this._value = null
this.callBackFuncs = []
this.rejCallBackFuncs = []
handle(this._resolve, this._reject)
}
_resolve(val) {
console.log(this)
if (this._status !== PENDDING) return
this._status = FULLFILLED
this._value = val
this.callBackFuncs.forEach(fn => {
fn()
})
}
_reject() {
if (this._status !== PENDDING) return
this._status = REJECTED
this.rejCallBackFuncs.forEach(fn => {
fn()
})
}
then(onFulFilled) {
if (this._status === PENDDING) {
this.callBackFuncs.push(onFulFilled)
}
if (this._status === FULLFILLED) {
onFulFilled()
}
}
}
new MPromise((resolve, reject) => {
resolve()
})
为什么这段代码打印出来的this是undefined,这里不是匿名函数调用吗,不应该是window吗### 问题描述
问题出现的环境背景及自己尝试过哪些方法
相关代码
粘贴代码文本(请勿用截图)
Class 是es6的语法,默认启动的是严格模式;严格模式下this是指向 undefined 的;