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)
通过递归实现。
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)
通过递归实现。
转载于:https://www.cnblogs.com/DaYesahh/p/11448395.html