Created
January 13, 2016 11:13
-
-
Save stasgavrylov/f164b3f67d79ee2edc2f to your computer and use it in GitHub Desktop.
This file contains 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(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