Skip to content

Instantly share code, notes, and snippets.

@tpps88206
Created December 11, 2020 09:05
Show Gist options
  • Save tpps88206/d2e24fcbabbb08be85027a2e909d4a2a to your computer and use it in GitHub Desktop.
Save tpps88206/d2e24fcbabbb08be85027a2e909d4a2a to your computer and use it in GitHub Desktop.
在 JavaScript 中實作 debounce 函數
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