Skip to content

Instantly share code, notes, and snippets.

@stasgavrylov
Created January 13, 2016 11:13
Show Gist options
  • Save stasgavrylov/f164b3f67d79ee2edc2f to your computer and use it in GitHub Desktop.
Save stasgavrylov/f164b3f67d79ee2edc2f to your computer and use it in GitHub Desktop.
function _debounce(callable, wait)
{
var id
function call(context, list)
{
requestAnimationFrame(function()
{
callable.apply(context, list)
id = 0
})
}
return function()
{
if (id) clearTimeout(id)
id = setTimeout(call, wait, this, arguments)
}
}
function _throttle(callable, wait)
{
var id
function call(context, list)
{
requestAnimationFrame(function()
{
callable.apply(context, list)
id = 0
})
}
return function()
{
if (id) return
id = setTimeout(call, wait, this, arguments)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment