function promiseTest () {
this.status = 'pending' // 2.1
this.msg = '' // 存储value与reason 成功或者失败的返回值
let process = arguments[0],
that = this
process (function () {
that.status = 'resolve'
that.msg = arguments[0]
}, function () {
that.status = 'reject'
that.msg = arguments[0]
})
return this
}
promiseTest.prototype.then = function () {
return new promiseTest((r,j) => {
if (this.status === 'resolve') {
var res = arguments[0](this.msg);
r(res);
} else if (this.status === 'reject' && arguments[1]) {
arguments[1](this.msg)
}
});
}
var pT = new promiseTest((r,j) => {
r('cheng-gong')
}).then((res) => res+'ww')
03-08
592
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-23
485
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)