export class Debounce { private delay: number; private timeoutID: number | null; private lastExec: number; private callback: Function; private args?: any[]; constructor(delay: number, callback: Function) { this.delay = delay; this.lastExec = 0; this.timeoutID = null; this.callback = callback; } exec(...args: any[]) { if (this.timeoutID) { // console.log("clear id" + this.timeoutID); clearTimeout(this.timeoutID); } // this.args = args; this.timeoutID = setTimeout(() => { this.callback(args); }, this.delay); } run() { this.callback(this.args); } }