promise学习理解笔记
一.promise的状态
pending - 进行中
fulfilled - 成功(接受)
rejected - 失败(拒绝)
resolve执行 (pending ==>fulfilled )
执行接受状态的回调函数(),并将返回值作为接受状态的回调函数的参数值
reject执行 (pending ==>rejected )
执行拒绝状态的回调函数(reject),并将返回值作为拒绝状态的回调函数的参数值
promise的状态只能从pending 改变为 fulfilled 或rejected 中的一个,一旦改变就无法再被改变,改变状态用的是resolve()与reject()这两个方法
二.then .catch与.finally
1.then与.catch
then方法共有两个参数,一个接受状态的回调函数,一个拒绝状态的回调函数
promise.then(function(value) {
// success
fulfilled状态时执行的回调
}, function(error) {
// failure
rejected状态时执行的回调
});
then的返回值,分为三种 return 值