ES9(2018)——Promise 升级版
作者:互联网
ES9中Promise是如何“兜底”操作的?
function Gen(time){ return new Promise((resolve,reject)=>{ setTimeout(function(){ if(time<500){ reject(time); }else{ resolve(time); } },time) }) } Gen(Math.random()*1000) .then(val=>console.log('resolve',val)) .catch(err=>console.log('reject',err)) .finally(()=>{console.log('finish')})//关闭数据库,保证数据库是断开的 //resolve 564.8225885780598 //finish //多刷几次,输出会变 //reject 94.27830818104587 //finish
标签:finish,console,log,ES9,resolve,Promise,2018,reject 来源: https://www.cnblogs.com/sunnywindycloudy/p/13055026.html