防抖

防抖函数 func是用户传入需要防抖的函数 wait是等待时间

1
2
3
4
5
6
7
8
9
10
11
function debounce(func, wait = 50) {
let timer = 0;
return function (...args) {
if (timer) clearTimeout(timer);
timer = setTimeout(() => {
timer = setTimeout(() => {
func.apply(this, args)
}, wait)
})
}
}