JingchaoZhao / js-learning

knowledge of webs
0 stars 0 forks source link

tips: Promise #14

Open JingchaoZhao opened 5 years ago

JingchaoZhao commented 5 years ago

Fulfilled (resolve)

Rejected (reject)

unResolved (pending)

JingchaoZhao commented 5 years ago

new Promise((resolve, reject) => {console.log(1); resolve(2)}).then(result => console.log(result)).catch(err => console.log(err)); console.log(3);

JingchaoZhao commented 5 years ago

Promise.resolve 快捷模式

Promise.resolve(32).then((value) => console.log(value))

JingchaoZhao commented 5 years ago

Promise.reject

Promise.reject(new Error("Boom")).catch(err => console.log(err))