防抖函数

44 阅读1分钟
    // 防抖 函数
    let timer;
    function debounce(fn, delay) {
      if (this.timer) clearTimeout(this.timer);
      timer = setTimeout(() => {
        fn()
      }, delay)
    },
    function a(){
        console.log("函数被调用");
    }
    // 调用
    debounce(a,300);