From: Ardis Lu Date: Fri, 13 Sep 2024 02:30:52 +0000 (-0700) Subject: Simplify debounce function X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=0ee2d9875ac2f40af3ac8c47e26dd4f513204f0c;p=ardislu.dev Simplify debounce function No need to pass `this` because it's not being called on an object. --- diff --git a/script.js b/script.js index c5f1e1b..306ad52 100644 --- a/script.js +++ b/script.js @@ -65,7 +65,7 @@ function debounce(fn, wait) { let timeoutId; return (...args) => { clearTimeout(timeoutId); - timeoutId = setTimeout(() => fn.apply(this, args), wait); + timeoutId = setTimeout(() => fn(...args), wait); } }