You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Hook up interceptors middlewarevarchain=[dispatchRequest,undefined];varpromise=Promise.resolve(config);this.interceptors.request.forEach(functionunshiftRequestInterceptors(interceptor){chain.unshift(interceptor.fulfilled,interceptor.rejected);});this.interceptors.response.forEach(functionpushResponseInterceptors(interceptor){chain.push(interceptor.fulfilled,interceptor.rejected);});while(chain.length){promise=promise.then(chain.shift(),chain.shift());}
标准
通过阅读Promises/A+规范发现,该规范明确强调了不会说明
Promise
是如何create
、fulfill
和reject
的, 仅仅是提供then
方法的操作. 其中的内容大部分围绕then
方法,甚至也可以说Promises/A+
规范就是关于then
的操作手册.也就是说, 标准并没有规定我们常用的catch
、all
等方法.三种状态
pending
, 该状态可以转变成其他两种状态fulfilled
状态下有一个不可变更的值rejected
状态下有一个不可变更的原因ps.不可变更的意思是
===
then
方法promise
提供的then
方法, 在这个方法中有两个参数onFulfilled、onRejected
,这两个参数是非必填的.onFulfilled, onRejected的判断过程
onFulfilled
和onRejected
是optional
参数,如果是非函数的,则会忽略掉.onFulfilled
函数:promise
处于fulfilled状态后才可以调用实战
参考
The text was updated successfully, but these errors were encountered: