Skip to content

Instantly share code, notes, and snippets.

@yckart
Forked from 140bytes/LICENSE.txt
Last active March 8, 2019 10:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yckart/6387878 to your computer and use it in GitHub Desktop.
Save yckart/6387878 to your computer and use it in GitHub Desktop.
debounce
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
};
}
function(a,b,c,d){return function(){d=this;clearTimeout(c);c=setTimeout(function(){a.apply(d,arguments)},b||100)}}
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.
{
"name": "debounce",
"description": "Delays a function to a specified number of milliseconds.",
"keywords": [
"delay",
"debounce",
"wait",
"function",
"functional"
]
}
<!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>
@shinsenter
Copy link

arguments is not working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment