js Promise
Promise抽象的表示一个异步操作
三状态
pending 最初状态
fulfilled 成功状态 返回的状态码 200-299
rejected 拒绝状态
let p=new Promise((resolve,reject)=>resolve()); setTimeout(console.log,0,p);
调用resolve会切换到fulfilled状态
调用reject会切换到rejected状态,并抛出错误
//1秒后再输出a let p=new Promise((resolve,reject)=>setTimeout(resolve,1000)) p.then(()=>console.log('a')) console.log('b')
使用pPomise
创建 Promise
Promise.all()
Promise.race()
Promise.resolve(x);
Promise.reject(x);