Promise实例的then方法

时间:2020-12-18 12:46:53   收藏:0   阅读:3
1 promise.then(function(value) {
2   // success
3 }, function(error) {
4   // failure
5 });

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

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

第一个回调函数参数:

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

第二个回调函数参数:

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

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

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!