我记得我之前不是写过防抖节流吗?
防抖和节流实现_数据

防抖(debounce)

      debounce(fn, wait) {
        let timer = null
        return function() {
          timer && clearTimeout(timer)
          timer = setTimeout(() => {
            fn.apply(this, arguments)
          }, wait)
        }
      }

节流(throttle)

      throttle(fn, time) {
        let oldTime = Date.now()
        return function() {
          let nowTime = Date.now()
          if(nowTime - oldTime > time) {
            fn.apply(this, arguments)
            oldTime = nowTime
          }
        }
      }

实战运用