节流函数

function throttle(fn, delay){
  let timer = null
  return function(...args) {
    if(timer) return
    let _this = this
    timer = setTimeout(() => {
      fn.apply(_this, args)
      timer = null
    }, delay)
}

你可能感兴趣的:(节流函数)