美文网首页
2022-01-06

2022-01-06

作者: 荆轲987 | 来源:发表于2022-01-06 10:50 被阅读0次
 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

      本文链接:https://www.haomeiwen.com/subject/anilcrtx.html