setTimeout模拟setInterval 第二遍

复制代码
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>用 setTimeout 模拟 setInterval</title>
  </head>
  <body>
    <script>
      function myInterval(func, delay) {
        function inside(a) {
          func(a);
          setTimeout(inside, delay, 5);
        }
        setTimeout(inside, delay, 5);
      }
      myInterval(like, 1000);
      function like(a) {
        console.log(a);
      }

      function newInterval(func, delay) {
        function insede(a) {
          func(a);
          setTimeout(inside, delay, 5);
        }
        setTimeout(inside, delay, 5);
      }
      newInterval(like,1000,5);
      function like(5){
        console.log(5);
      }
    </script>
  </body>
</html>
复制代码

 

posted @   苹果π  阅读(25)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
点击右上角即可分享
微信分享提示