Skip to content

Instantly share code, notes, and snippets.

@eldargab
Created September 24, 2012 17:11
Show Gist options
  • Save eldargab/3777055 to your computer and use it in GitHub Desktop.
Save eldargab/3777055 to your computer and use it in GitHub Desktop.
throttle function
function throttle (fn, timeout) {
var ctx, args, wait = false
return function () {
if (wait) {
ctx = this
args = arguments
return
}
wait = true
fn.apply(this, arguments)
setTimeout(function () {
wait = false
var _ctx = ctx
var _args = args
ctx = null
args = null
_args && fn.apply(_ctx, _args)
}, timeout)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment