setTimeOut实现setInterval:递归调用
timerFn()
function timerFn(){
console.log("1")//要执行的代码
var timer=setTimeout(() => {//间隔一定时间递归执行一次
timerFn()
clearInterval(timer)
}, 1000);
}
setInterval实现setTimeOut:内部清除定时器
var timer=setInterval(()=>{
console.log("1")
clearInterval(timer)
},2000)