用setTimeout实现setInterval

1 function mySetInterval(fn,time){
2     function inner(){
3         fn();
4         setTimeout(inner,time);
5     }
6     inner()
7 }
8 
9 mySetInterval(() => {console.log("sss")}, 1000)

通过递归实现。

猜你喜欢

转载自www.cnblogs.com/DaYesahh/p/11448395.html