function debounce (fn, wait = 200) {
var timerId = null;
function helper () {
if (timerId) {
clearTimeout(timerId);
timerId = null;
}
timerId = setTimeout (function () {
fn();
}, wait)
}
return helper;
}
// 高频计算
function calc () {
console.log('calc trigger');
}
// calc();
// calc();
// calc();
// calc();
// calc();
const debouncedCalc = debounce(calc);
debouncedCalc();
debouncedCalc();
debouncedCalc();
debouncedCalc();
debouncedCalc();