2025-05-27 15:46:31 +08:00

25 lines
509 B
JavaScript
Executable File

/**
* 用来作一些全局的js方法声明
*
*/
// 防抖函数实现
function debounce(func, wait) {
let timeout;
return function (...args) {
clearTimeout(timeout);
timeout = setTimeout(() => func(...args), wait);
};
}
// 节流函数
function throttle(fn, delay) {
let lastTime = 0;
return function (...args) {
const now = Date.now();
if (now - lastTime >= delay) {
fn.apply(this, args);
lastTime = now;
}
};
}