馬老師Rust語言
滾動事件
function debounce(time, callback) {
?let timer;
?return (...args) => {
? ?timer && clearTimeout(timer);
? ?timer = setTimeout(() => {
? ? ?callback(args);
? ?}, time);
?}}const fn = debounce(2000, () => console.log("Hello!"));fn();setTimeout(fn, 1000);
標(biāo)簽: