定时器
let timer;
const run = function (id) {
let counter = 0;
return setInterval(() => {
counter += 1;
if (counter >= 11) {
clearInterval(timer);
} else {
this.function{功能函数}(id);
}
}, 2000);
};
function{外层函数}(id) {
// 自动刷新,2s一次
timer = run.call(this, id);
},
function{功能函数} {
//某些功能
×××
clearInterval(timer);
}