防抖函数 模板~

 

防抖函数一直是面试的重点,特此整理,写个百八十遍~

<body>
    <div id="button">点击按钮</div>
    <script>
      const button = document.getElementById('button');
      function payMoney() {
        console.log('我要支付啦');
      }
      function deBounce(func, delay) {
        let timer;
        return function () {
          clearTimeout(timer);
          let context = this;
          let args = arguments;
          timer = setTimeout(function () {
            func.apply(context, args);
          }, delay);
        };
      }
    </script>
  </body>

参考 :哔哩哔哩=》》技术蛋老师

posted @ 2022-03-18 15:21  苹果π  阅读(40)  评论(0)    收藏  举报