Skip to content

Instantly share code, notes, and snippets.

@webVueBlog
webVueBlog / 封装防抖
Last active January 18, 2022 09:09
封装防抖(ts)
export class Debounced {
public use = (func: Function, delay: number, immediate: boolean = false): Function {
let timer: any = undefined
return (...args: any) => {
if (immediate) {
func.apply(this, args)
immediate = false
return
}
clearTimeout(timer)