面试题
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Promise回调</title>
</head>
<style>
.button {
color: #2d8cf0;
border-color: #2d8cf0;
background-color: #fff;
}
</style>
<body>
<input type="file" class="button">
<script>
let count = 0
let t1 = (resovle) => {
let timer = Math.random()*1000
setTimeout(()=>{
console.log('t1 done')
count++
count === 2 && resovle()
}, timer)
}
let t2 = (resovle) => {
let timer = Math.random()*1000
setTimeout(()=>{
console.log('t2 done')
count++
count === 2 && resovle()
}, timer)
}
let t3 = (resovle) => {
let timer = Math.random()*1000
setTimeout(()=>{
console.log('t3 done')
count++
count === 2 && resovle()
}, timer)
}
let p1 = new Promise(t1)
let p2 = new Promise(t2)
let p3 = new Promise(t3)
Promise.race([p1, p2, p3]).then(() => {
console.log('任意两个任务调用完成,执行回调~~~~~~~~~~')
})
</script>
</body>
</html>