I am interested in the \"debouncing\" function in javascript, written here : http://davidwalsh.name/javascript-debounce-function
Unfortunately the code is not explai
Simple Debounce method in javascript
Debounce Method
// JS File
var debouncebtn = document.getElementById('debounce');
function debounce(func, delay){
var debounceTimer;
return function () {
var context = this, args = arguments;
clearTimeout(debounceTimer);
debounceTimer = setTimeout(function() {
func.apply(context, args)
}, delay);
}
}
// Driver Code
debouncebtn.addEventListener('click', debounce(function() {
document.getElementById('message').innerHTML += '
Button only triggeres is every 3 secounds how much every you fire an event';
console.log('Button only triggeres in every 3 secounds how much every you fire an event');
},3000))
Runtime Example JSFiddle: https://jsfiddle.net/arbaazshaikh919/d7543wqe/10/