假设有这样一个定时器:
let auto = setInterval(right, 1000)
clearInterval(auto)
此时如果想重启定时器auto,应当这样写
//正确写法
auto = setInterval(right, 1000)
//错误写法
let auto = setInterval(right, 1000)
//错误写法,会创建新的计时器,如果这句话被诸如mouseleave触发,反复触发将创造非常多计时器
setInterval(right, 1000)
标签:定时器,setInterval,auto,clearInterval,重新启动,right,1000
From: https://www.cnblogs.com/exungsh/p/17092710.html