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 newInterval(func, delay) {
        function inside(a) {
          func(a);
          setTimeout(inside, delay, 5);
        }
        setTimeout(inside, delay, 5);
      }
      newInterval(like, 1000);
      function likc(a) {
        console.log(a);
      }
    </script>
  </body>
</html>

 

posted @ 2022-05-02 18:57  苹果π  阅读(16)  评论(0编辑  收藏  举报