JSFiddle - React, Tailwind, and code Playground
by mOrloff
JavaScript
var foo = function(xyz) {
alert(xyz);
};
function setter(func, arg1, arg2) {
return {
fn: func,
arg1: arg1,
arg2: arg2
};
}
function debounce(someObject) {
var duration = someObject.arg2 || 100;
var timer;
if (timer) {
clearTimeout(timer);
}
timer = setTimeout(function() {
someObject.fn(someObject.arg1);
timer = 0;
}, duration);
}
var toggle = true;
if(toggle){
debounce(setter(foo, 'The best things in life are worth waiting for.', 1250));
}else{
foo('Instant gratification is sweet!!');
}