Closed opacitySun closed 3 years ago
function mySetInterVal(fn, a, b){ let ms = a; const timer = setInterval(() => { console.log(ms); fn(); ms += b; }, ms); return () => { if(timer) clearInterval(timer); } }
const myFn = mySetInterVal(() => { console.log(1111); }, 1000, 2000);
//清除轮询 myFn();
function mySetInterVal(fn, a, b){ let ms = a; const timer = setInterval(() => { console.log(ms); fn(); ms += b; }, ms); return () => { if(timer) clearInterval(timer); } }
const myFn = mySetInterVal(() => { console.log(1111); }, 1000, 2000);
//清除轮询 myFn();