举例:
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>