字节一面代码题2021/9/6
作者:互联网
题目:给一个promise,它如果十秒内可以执行出结果就打印出结果,如果十秒内解决不出来就会直接返回失败
let p = new Promise((resolve, reject) => {
setTimeout(() => {
resolve('success')
}, Math.random()*20000)
setTimeout(() => {
reject('fail')
}, 10000)
})
p.then((data) => {
console.log(data)
}).catch(e => console.log(e))
标签:console,log,代码,十秒,2021,reject,setTimeout,data,字节 来源: https://blog.csdn.net/qq_44606245/article/details/120150383