acdr-ui/dist/dev/mp-weixin/sheep/helper/throttle.js

22 lines
460 B
JavaScript
Raw Normal View History

2024-09-19 07:20:14 +08:00
"use strict";
let flag;
function throttle(func, wait = 500, immediate = true) {
if (immediate) {
if (!flag) {
flag = true;
typeof func === "function" && func();
setTimeout(() => {
flag = false;
}, wait);
}
} else if (!flag) {
flag = true;
setTimeout(() => {
flag = false;
typeof func === "function" && func();
}, wait);
}
}
exports.throttle = throttle;
//# sourceMappingURL=throttle.js.map