手写代码之防抖

function debounce(func, ms = 1000) {
  let timer;
  return function (...args) {
    if (timer) {
      clearTimeout(timer);
    }
    timer = setTimeout(() => {
      func.apply(this, args);
    }, ms);
  };
}

 

posted @ 2024-01-30 17:31  行走的蒲公英  阅读(8)  评论(0编辑  收藏  举报