I have problems when certain functions in my code are executed in quick succession. I thought maybe a few lines of javascript would prevent trigger-happy folks.
So here’s what I hoped to use.
function change(){
if(mod == 1 || mod == null){
var mod=2;
//function goes here
window.setTimeout(function(){var mod=1;}, 500);
}
Is there a way to do this that actually works?
I also feel there should be a more global approach to this I’m not thinking of.
You can throttle or debounce the callback. There’s a nice (jQuery-optional) library that wraps all this up for you: jQuery throttle/debounce.
Since you just commented that you want to
it sounds like you’re looking for the debounce use-case.