A debounce function in JavaScript, inspired from David Walsh's Blog post.
window.addEventListener("resize", debounce(function(event) {
console.log(event);
}, 150));
function debounce(func, wait) { | |
var timeout; | |
return function() { | |
var context = this, args = arguments; | |
var later = function() { | |
timeout = null; | |
func.apply(context, args); | |
}; | |
clearTimeout(timeout); | |
timeout = setTimeout(later, wait); | |
}; | |
}; |
A debounce function in JavaScript, inspired from David Walsh's Blog post.
window.addEventListener("resize", debounce(function(event) {
console.log(event);
}, 150));