简洁、易读
1. 封装定时器函数
2. setInterval 与 clearInterval
function count(start, end) { let count = start; let timer; let myCallback = () => { console.log(count++); if (count > end) clearInterval(timer); } myCallback(); timer = setInterval(myCallback, 100); return { cancel: () => clearInterval(timer) } }