const loopFunc=(callback,time)=>{ let timer; const run=()=>{ timer=setTimeout(()=>{ callback(); run() },time||3000); } run(); return ()=>clearTimeout(timer) } let t=loopFunc(()=>console.log(new Date()),2000) //销毁定时器 调用 t() setTimeout(()=>{ t() },6000);