setInterval 在每次把任务加入队列前,都会判断队列中有没有上次的任务,如果有则不会加入,, setTimeout则会直接将任务加到对列中
setInterval: 缺点: 有时会漏掉某个任务过程
解决办法,,用setTimeout模拟setInterval
function test(){
console.log('a')
}
function timer(){
test()
setTimeout(()=> {
timer()
}, 1000)
}
timer(); // 开始调用