Promise实例的then方法

1 promise.then(function(value) {
2   // success
3 }, function(error) {
4   // failure
5 });

then本质上是一个函数,因为then存在于对象之中,所以又叫做方法。将then当做一个函数就ok了。

then有两个参数,这两个参数都是回调函数。

第一个回调函数参数:

当promise对象的状态变为resolved时调用

第二个回调函数参数:

当promise对象的状态变为rejected时调用。

这两个函数的参数都是Promise对象所传出来的值。

原文地址:https://www.cnblogs.com/flyover/p/14129151.html