/*** * ------------------- * 此文件用于优化js方法 * ------------------- * */ // 防抖 export function deBounce(fn: T, delay: number): () => void { let timer: any; return function (): void { const args: any[] = Array.prototype.map.call(arguments, (val) => val); if (timer) { clearTimeout(timer); } timer = setTimeout( () => { typeof fn === 'function' && fn.apply(null, args); clearTimeout(timer); }, delay > 0 ? delay : 100 ); }; }