Created
December 11, 2020 09:05
-
-
Save tpps88206/d2e24fcbabbb08be85027a2e909d4a2a to your computer and use it in GitHub Desktop.
在 JavaScript 中實作 debounce 函數
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) { | |
| var timer | |
| return function () { | |
| var context = this | |
| var args = arguments | |
| clearTimeout(timer) | |
| timer = setTimeout(function () { | |
| fn.apply(context, args) | |
| }, delay) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment