常用函数

发布时间 2023-09-04 09:30:10作者: 衔玉凌枝
debounce(fn, delay=500) {
          debounce(fn, delay=500) {
      let timer;
      return function() {
        const that = this;
        const args = arguments;
        if(timer) {
          clearTimeout(timer);
        }
        timer = setTimeout(() => {
          timer = null;
          fn.apply(that, args);
        }, delay)
      }
    }

  防抖函数