美文网首页JavaScript
Promise基础教程

Promise基础教程

作者: WebGiser | 来源:发表于2022-02-16 10:48 被阅读0次

    定义异步函数

        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);
    

    相关文章

      网友评论

        本文标题:Promise基础教程

        本文链接:https://www.haomeiwen.com/subject/uhnrlrtx.html