美文网首页
promise的理解

promise的理解

作者: 风雪之隅_b6f7 | 来源:发表于2019-04-10 10:22 被阅读0次

    //#1 返回promise实例给then

    doSomething().then(()=>{

        return doSomethingElse();

    })

    //执行步骤

    dosomething=>doSomethingElse(undefined)=>finalHandler(result of dosomethingElse)

    //#2 不返回promise实例给then相当于返回空

    doSomething().then(()=>{

        doSomethingElse();

    })

    //执行步骤

    dosomething=>dosomethingElse(undefined)=>finalHandler(undefined)

    //#3then里面立即执行函数返回的是promise实例,且和dosomething 同时执行,在同一个栈中执行

    doSomething().then(doSomethingElse());

    //执行步骤

    dosomething()            =>    finalHandler(result of dosomething)

    dosomethingElse(undefined)=>

    //#4 dosomethingElse作函数传进去,then中默认可以传两个函数作为参数(resolve,reject)

    doSomething().then(doSomethingElse);

    //执行步骤

    dosomething=>dosomethingElse(result of dosomething)=>finalHandler(result of dosomethingElse)

    相关文章

      网友评论

          本文标题:promise的理解

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