前端防抖与节流

 

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('点击输出');
};
posted @ 2022-05-22 22:30  暴龙机甲兽  阅读(38)  评论(0)    收藏  举报