-
-
Save yckart/6387878 to your computer and use it in GitHub Desktop.
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 ( | |
a, // the function to call after delay | |
b, // The time to delay (optional) | |
c, // timer-placeholder | |
d // this-placeholder | |
) { | |
return function () { | |
d = this; // put this in a variable | |
clearTimeout(c); // clear timers timeout | |
c = setTimeout(function () { // set timers timeout | |
a.apply(d, arguments); // function to call after timeout | |
}, b || 100); // timeout after given delay | |
}; | |
} |
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(a,b,c,d){return function(){d=this;clearTimeout(c);c=setTimeout(function(){a.apply(d,arguments)},b||100)}} |
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
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
Version 2, December 2004 | |
Copyright (C) 2013 Yannick Albert <http://yckart.com> | |
Everyone is permitted to copy and distribute verbatim or modified | |
copies of this license document, and changing it is allowed as long | |
as the name is changed. | |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
0. You just DO WHAT THE FUCK YOU WANT TO. |
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
{ | |
"name": "debounce", | |
"description": "Delays a function to a specified number of milliseconds.", | |
"keywords": [ | |
"delay", | |
"debounce", | |
"wait", | |
"function", | |
"functional" | |
] | |
} |
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
<!DOCTYPE html> | |
<title>debounce: Delays an event to a specified number of milliseconds.</title> | |
<b id="ret">Move your mouse and check the output.</b> | |
<script> | |
var debounce = function(a,b,c,d){return function(){d=this;clearTimeout(c);c=setTimeout(function(){a.apply(d,arguments)},b||100)}}; | |
document.onmousemove = debounce(function() { | |
document.getElementById('ret').innerHTML = new Date().getTime(); | |
}, 400); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
arguments
is not working