function P(callback) {
this.status = 'pending';
this.value = '';
var that = this;
function resolve(params) {
that.status = 'resolved'that.value = params
}
function reject(params) {
that.status = 'rejected'that.value = params
}
callback(resolve, reject)
}
P.prototype.then = function(fn) {
if (this.status === 'resolved') {
var value = fn(this.value) if (value instanceof P) {
this.status = value.status;
this.value = value.value
} else {
this.status = 'resolved'this.value = value
}
}
return this
}
P.prototype.
catch = function(fn) {
if (this.status === 'rejected') {
var value = fn(this.value) if (value instanceof P) {
this.status = value.status;
this.value = value.value
} else {
this.status = 'resolved'this.value = value
}
}
return this
}
console