防抖函数

// 设计一个防抖函数
function debounce (fn,delay) {
  let timer = null;
  return function() {
    clearTimeout(timer);
    timer = setTimeout(()=> {
      fn.apply(this,arguments);
    }, delay || 300)
}
}

 

posted @ 2020-10-10 18:31  Nextfuture  阅读(255)  评论(0编辑  收藏  举报