function throttle(callback, duration) {
console.log(this);
let time;
return function (data) {
console.log(this);
if (!time) {
time = setTimeout(() => {
console.log(this);
callback.apply(this, arguments);
}, duration);
time = null;
}
};
}
function fn(params) {
console.log(params);
}
let func = throttle(fn, 1000);
console.log(func("你好"));
简单的节流函数实现
于 2023-09-22 14:22:46 首次发布