JS ES6 Promise Chaining

后端 未结 5 2066
南笙
南笙 2020-12-10 14:28

I\'m trying to learn how to use promises, but am having trouble comprehending the chaining. I assume that with this code, both promises will run. Then when I call test.then(

5条回答
  •  感情败类
    2020-12-10 14:50

    You need to return next promise from the then callback:

    test.then(function(data) {
        console.log(data);
        return test2;
    }).then(function(data) {
        console.log(data);
    });
    

提交回复
热议问题