Promise基础教程
2022-02-16 本文已影响0人
WebGiser
定义异步函数
testOne(resolve:any, reject:any){
setTimeout(() => {
resolve("one");
}, 3000);
}
testTwo(resolve:any, reject:any){
setTimeout(() => {
resolve("two");
}, 3000);
}
testThree(resolve:any, reject:any){
setTimeout(() => {
resolve("three");
}, 3000);
}
定义 Promise
let result = new Promise(this.testOne)
.then((resultOne)=>{
console.log(resultOne);
return new Promise(this.testTwo);
})
.then((resultTwo)=>{
console.log(resultTwo);
return new Promise(this.testThree);
})
.then((resultThree)=>{
console.log(resultThree);
});
console.log(result);