3 回答
TA贡献1804条经验 获得超7个赞
function poll (checkStatus, callback) {
const poll = (checkStatus, callback, time) => {
if (checkStatus()) {
callback()
} else {
setTimeout(() => {
console.log(new Date())
poll(checkStatus, callback, time * 1.5)
}, time)
}
}
poll(checkStatus, callback, 1000)
}
TA贡献2036条经验 获得超8个赞
按你采纳的想法,我觉得
function poll (checkStatus,callback,time) {
if(checkStatus()){
callback()
}else{
setTimeout(()=>{
poll(checkStatus,callback,time*1.5)
},time)
}
}
function checkStatus(){
return true;
}
function callback () {
console.log()
}
poll(checkStatus,callback,1000)
这样也行吧
添加回答
举报