JSFiddle - React, Tailwind, and code Playground
by syamsoul
JavaScript
let setTimeoutOnce = function(func, timeout){
if(typeof func != "function"){
console.log("ERROR:", "First parameter must be a function");
}else if(isNaN(timeout * 1)){
console.log("ERROR:", "Second parameter must be number");
}
let st = null;
this.exec = function(){
if(st == null){
st = true;
setTimeout(function(){
func();
st = null;
}, timeout);
}
}
}
let the_timeout = new setTimeoutOnce(function(){
alert('alright');
}, 5000);
the_timeout.exec();
the_timeout.exec();