防抖函数

33 阅读1分钟
  debounce(fun, wait){
    let timer = null
    return function(){
      let context = this, args = arguments
      if(timer) clearTimeout(timer)
      timer = setTimeout(function(){
        fun.apply(context, args)
      }, wait)
    }
  }