I have global setTimeout function as follow:
myTimer = function(){
var timer;
this.set = function(saveFormCB) {
timer = setTimeout(function() {
saveFormCB();
}, 10000)
};
this.clear = function() {
clearInterval(timer);
};
return this;
}();
Above will delay saveFormCB() execution 10 second if I do like below:
myTimer.clear()
myTimer.set(function () {
saveFormCB()
});
Some component need faster execution than 10 second, say 5 second. So I need dynamic delay for myTimer function. I did below but not working:
myTimer = function(a){
var timer;
this.set = function(saveFormCB) {
timer = setTimeout(function() {
saveFormCB();
}, a || 10000)
};
this.clear = function() {
clearInterval(timer);
};
return this;
}();
Any help would be appreciated
Thanks
ADDITIONAL INFO
myTimer execute on input event. Everytime no typing, myTimer will be executed and the value will be saved to db (with saveFormCB() function) after 10 second myTimer was executed