debounce.ts 285 B

12345678910
  1. // 防抖 https://www.30secondsofcode.org/js/s/debounce
  2. export default (fn: Function, ms = 0) => {
  3. let timeoutId: number | undefined;
  4. return function(...args: any[]) {
  5. clearTimeout(timeoutId)
  6. // @ts-ignore
  7. timeoutId = setTimeout(() => fn.apply(this, args), ms);
  8. }
  9. }