Skip to content

Instantly share code, notes, and snippets.

@pongo
Last active May 24, 2025 09:04
Show Gist options
  • Save pongo/3e8a28bc8ac2ebf637a75d18d027577a to your computer and use it in GitHub Desktop.
Save pongo/3e8a28bc8ac2ebf637a75d18d027577a to your computer and use it in GitHub Desktop.
function debounce(fn, delay) {
let timer;
return function (...args) {
clearTimeout(timer);
timer = setTimeout(() => fn.apply(this, args), delay);
};
}
const obj = {
name: 'test',
method: function() {
console.log(this.name);
},
method2: debounce(function() {
console.log(this.name);
}, 100)
};
obj.method = debounce(obj.method, 100);
obj.method();
obj.method2();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment