ES9 Promise 拓展 Promise.prototype.finally()

// ES9 Promise 拓展 Promise.prototype.finally() // 成功失败都会执行

new Promise((resolve, reject) => {
setTimeout(() => {
// resolve('成功')
reject('fail')
}, 1000)
}).then(res => {
console.log(res)
}).catch(err => {
console.log(err)
}).finally(() => {
console.log('finally')
})
// 场景应用 使loading消失
// 数据库关闭操作

posted @ 2021-03-28 19:31  贺可英  阅读(55)  评论(0)    收藏  举报