高阶函数--节流功能
2021-03-20 本文已影响0人
摇裤儿
let btnName = document.getElementById("btn");
btnName.onclick = throttle(function () {
console.log(1);
}, 2000);
function throttle(fn,wait) {
let timer;
return function (...args) {
if (timer) return;
timer = setTimeout(() => (timer = null), wait);
return fn(args);
};
}