一个新的API: Promise.withResolvers
一个新的 promise api
为什么会有这个API
let res;
let rej;
new Promise((resolve, reject)=>{
res = resolve;
rej = reject;
});
新语法
const { promise, resolve ,reject } = Promise.withResolvers();
注意
- 语法较新,chrome 119 才支持
let res;
let rej;
new Promise((resolve, reject)=>{
res = resolve;
rej = reject;
});
const { promise, resolve ,reject } = Promise.withResolvers();