2022-01-06

 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)

你可能感兴趣的:(2022-01-06)