]> git.ardis.lu - ardislu.dev/commitdiff
Simplify debounce function
authorArdis Lu <ardisglu@gmail.com>
Fri, 13 Sep 2024 02:30:52 +0000 (19:30 -0700)
committerArdis Lu <ardisglu@gmail.com>
Fri, 13 Sep 2024 02:30:52 +0000 (19:30 -0700)
No need to pass `this` because it's not being called on an object.

script.js

index c5f1e1ba9dd40538b1f5460c28fa6576956ae0b0..306ad52cc366b476b8ca6bc08ecd585d684b9fcb 100644 (file)
--- 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);
   }
 }
 
This page took 0.042915 seconds and 4 git commands to generate.