我正在尝试将 Promise 函数重写为异步函数
当我的承诺奏效时
function boxColor (time) {
return new Promise ((res, rej) => {
setTimeout(() => {
res(box.style.backgroundColor = randomColor())
}, time)
})}
我不能让它与异步一起工作
async function newBoxColor(time) {
try {
setTimeout(() =>{
return box.style.backgroundColor = randomColor()
}, time)
} catch (error) {
throw error
} }
我的错误是什么?