前端防抖与节流
const debounce = (fn, dealy) => {
let timeOutId = null;
return function (...agrs) {
console.log(agrs, 'args');
clearTimeout(timeOutId);
timeOutId = setTimeout(() => {
fn(...agrs);
}, dealy);
};
};
const throttle = (fn, dealy) => {
let createTime = 0;
return function (...args) {
const nowTime = Date.now();
if (nowTime - createTime > dealy) {
fn(...args);
createTime = nowTime;
}
};
};
const click = () => {
console.log('点击输出');
};