Skip to content

throttle

创建一个节流函数,该函数每 delay 毫秒最多只调用一次 fn

使用

ts
import { throttle } from 'rattail'

const throttledFn = throttle(() => {
  // do something, it will be called at most 1 time per second
}, 1000)

window.addEventListener('resize', throttledFn)

参数

参数类型默认值
fnFunction
delaynumber200

返回值

类型
Function