function simulateSetInterval(fn, t) {
let timer = null;
function interval() {
timer = setTimeout(() => {
fn()
interval()
}, t);
}
interval();
return {
cancel:()=>{
clearTimeout(timer)
}
}
}
const cancel = simulateSetInterval(() => {
console.log(1)
}, 300)
网友评论