function MyPromise(fun) {
let self = this;
self.then = function (resolve, error) {
resolve&&resolve(self.value);
error&&error(self.errValue);
return this;
}
function resolve (value) {
self.value = value;
}
function error (value) {
self.errValue = value;
}
fun(resolve, error);
}
function test () {
return new MyPromise(function(resolve,error){
resolve("我是个正确值");
error('我是个错误值');
});
}
test().then(function(result){
console.info('result = ', result)
}).then(function(result){
console.info('result = ', result)
});