js实现节流防抖动
代码:
<body>
<button type="button"id="btn">点击</button>
</body>
<script type="text/javascript">
let btn=document.getElementById("btn")
function debounce(func,await){
let timer;
return function(){
let context=this;
let args=arguments;
if(timer){
clearTimeout(timer)
}
timer=setTimeout(()=>{
func.call(context,args)
},await)
}
}
btn.onclick=debounce(function(){
console.log("hello world")
},1000)
</script>