// 未添加异步处理等其他边界情况
// ①自动执行函数,②三个状态,③then
function myPromise(fn){
this.status = 'pending';
this.msg = '';
fn && fn(function(value){
this.status = 'resolved';
this.msg = value
}.bind(this),function(reason){
this.status = 'rejected';
this.msg = reason
}.bind(this))
}
myPromise.prototype.then = function(resolve,reject){
if(this.status == 'resolved'){
resolve(this.msg)
}
if(this.status == 'rejected'){
reject(this.msg)
}
}
//测试代码
var p = new myPromise(function(resolve,reject){
resolve('1234');
})
p.then(function(success){
console.log(success)
},function(fail){
console.log(fail)
})