function PDeferred() {
debugger;
this.core;
this.res;
this.rej
function init(_obj) {
debugger
return new Promise(function (res, rej) {
debugger;
_obj.setResolve(res);
_obj.setReject(rej);
})
}
this.core = init(this);
}
(function(){
this.then = function(fn_1, fn_2){
debugger;
return this.core.then(fn_1, fn_2);
}
this.resolve = function(){
debugger;
this.res();
}
this.reject = function(){
debugger;
this.rej();
}
this.setResolve = function(res){
this.res = res;
}
this.setReject = function(rej){
this.rej = rej;
}
this.promise = function(){
return this.core;
}
}).call(PDeferred.prototype);
function job_1(){
debugger;
var def = new PDeferred();
setTimeout(function() {
def.resolve();
}, 1000);
return def.promise();
}
job_1().then(function(){
var def = new PDeferred();
console.log('then_1 start');
setTimeout(function() {
console.log('then_1 end');
def.resolve();
}, 1000);
return def.promise();
}).then(function(){
console.log('then_2');
});