Last active
May 24, 2025 09:04
-
-
Save pongo/3e8a28bc8ac2ebf637a75d18d027577a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function debounce(fn, delay) { | |
let timer; | |
return function (...args) { | |
clearTimeout(timer); | |
timer = setTimeout(() => fn.apply(this, args), delay); | |
}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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