当业务功能满足以下三个条件:

1、频繁触发

2、耗时操作

3、只关心最终结果

function debounce(fn,deplay=300){
    let timerId;
    return function(...args){
      if(timerId){
        clearTimeout(timerId);
      }
      timerId=setTimeout(()=>{
        fn.call(this,...args);
      },deplay)
    }
  }

 

posted on 2025-04-17 09:28  小菟同学  阅读(7)  评论(0)    收藏  举报

……