Archive
throttle

throttle

lodash의 throttle을 직접 구현함 함수입니다.

this에 타입 에러가 출력되시는 분들은 tsconfig.json에서 noImplicitThisfalse 로 두시면 됩니다.

services/utils/index.ts
export function throttle(func: Function, wait: number) {
  let waiting = false
  return function () {
    if (!waiting) {
      func.apply(this, arguments)
      waiting = true
      setTimeout(() => {
        waiting = false
      }, wait)
    }
  }
}
tsconfig.json
{
  "noImplicitThis": false
}

© 2023 kidow. All rights reserved.
안녕하세요?