📅  最后修改于: 2022-03-11 15:04:21.507000             🧑  作者: Mango
const debounce = (fn, delay) => {
let timer;
return function () {
clearTimeout(timer);
timer = setTimeout(fn, delay);
};
};
// Example
let count = 0;
const increaseCount = (num) => {
count += num;
console.log(count);
};
window.addEventListener('scroll', debounce(increaseCount.bind(null, 5), 200));