We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
连续点击,最后一次点击一秒后执行一次。
function debounce(fn, delay) { let timer = null; return () => { if (timer) { clearTimeout(timer); } timer = setTimeout(() => { fn(); }, delay); }; } const get = () => { console.log("debounce"); }; a = debounce(get, 1000); a();
连续点击,每隔一秒执行一次。
function throttle(fn, time) { let begin = new Date(); return function () { if (new Date() - begin < time) { return false; } fn(); begin = new Date(); }; } const get = () => { console.log(666); }; a = throttle(get, 1000);
The text was updated successfully, but these errors were encountered:
No branches or pull requests
防抖 debounce
连续点击,最后一次点击一秒后执行一次。
节流 throttle
连续点击,每隔一秒执行一次。
The text was updated successfully, but these errors were encountered: