debounce(防抖)
function debounce(func,wait) {
let timeout;
return function () {
clearTimeout(timeout); //有定时器就先清掉,始终保证只有一个定时器
timeout = setTimeout(() => {
func.apply(this,arguments);
timeout = null;
}, wait);
}
}
function logger(e) {
console.log('logger');
}
btn.addEventListener('click', debounce(logger,1000));