1.resolve
2.reject
3.手写
1.resolve
//构造函数上添加 resolve 方法
Promise.resolve = function (value) {
return new Promise((resolve, reject) => {
if (value instanceof Promise) {
value.then(
(val) => {
resolve(val)
},
(err) => {
reject(err)
}
)
} else {
resolve(value)
}
})
}
2.reject
Promise.reject = function (value) {
return new Promise((resolve, reject) => {
reject(value)
})
}