函数节流

这是工具类中的函数,用于被调用 gapTime指 这个限定的时间段  在这个时间段内,这个函数只执行一次

//函数节流
function throttle(fn, gapTime) {
  if (gapTime == null || gapTime == undefined) {
    gapTime = 1500
  }

  let _lastTime = null
  // 返回新的函数
  return function () {
    let _nowTime = + new Date()
    if (_nowTime - _lastTime > gapTime || !_lastTime) {
      fn.apply(this, arguments)   //将this和参数传给原函数
      _lastTime = _nowTime
    }
  }
}
调用过程:
toOrderdetail: util.throttle(function(e) {
    
  }, 2000), 

 




posted @ 2019-04-18 12:34  xiaoshen666  阅读(117)  评论(0编辑  收藏  举报