JS函数节流

举例:

 1     <button>按钮</button>
 2 
 3     <script>
 4         function throttle(method,context){
 5             clearTimeout(method.tId);
 6             method.tId = setTimeout(() => {
 7                 method.call(context);
 8             }, 1000);
 9         }
10 
11         function myFun(){
12             console.log("click")
13         }
14 
15         document.querySelector('button').addEventListener("click",function(){
16             throttle(myFun,window)
17         })
18     </script>

 

posted @ 2021-04-20 01:03  喵喵队立大功  阅读(133)  评论(0编辑  收藏  举报