Answers for "debounce polyfill"

2

javascript debounce function

// This is from David Walshes Blog Post 
// https://davidwalsh.name/javascript-debounce-function
// A very simplified but effective version of Underscores debounce function
function debounce(func, wait, immediate) {
	var timeout;
	return function() {
		var context = this, args = arguments;
		var later = function() {
			timeout = null;
			if (!immediate) func.apply(context, args);
		};
		var callNow = immediate && !timeout;
		clearTimeout(timeout);
		timeout = setTimeout(later, wait);
		if (callNow) func.apply(context, args);
	};
};
Posted by: Guest on February-08-2020
0

debounce polyfill

const debounce = (func, delay) => {
    let clearTimer;
    return function() {
        const context = this;
        const args = arguments;
        clearTimeout(clearTimer);
        clearTimer = setTimeout(() => func.apply(context, args), delay);
    }
}
Posted by: Guest on March-03-2021

Code answers related to "debounce polyfill"

Code answers related to "Javascript"

Browse Popular Code Answers by Language