javascript - How to unbind a binded button directly after starting task? -
hello have short question, have bound button "dothis()" if mouseenter cursor. current problem that, if mouseenter button while "dothis()" running, runs "dothis()" again. how can unbind him of it's function when dothis(); starts? idea unbind in "dothis()" self. work or there other better solution? aim button should run dothis(); , parallel unbinded, cant run dothis(); again, if call mainfunction(); again.
function mainfunction(){ bind(button, 'mouseenter', function() { dothis(); } }); } function dothis(){ ... }
thank u
instead of unbinding , rebinding, create flag, if flag true not run dothis. if false set flag true , run dothis. when dothis complete set flag false.
var dothisrunning = false; function mainfunction(){ bind(button, 'mouseenter', function() { if(dothisrunning){ return; } dothisrunning = true; dothis(); }); } functio dothis(){ /* ... */ //at end set false dothisrunning = false; }
Comments
Post a Comment