(function () { vared = []; Window. Lockable=function(LOCKF, options) {if(!arguments.length) {varCaller =Arguments.callee.caller; if(Ed.indexof (caller) = = = 1) {Ed.push (caller); Caller.unlock=function() {Ed.splice (Ed.indexof (caller),1); }; return; } return true; } varEmpty =function() {}, on= Options && Options.On | |empty, off= Options && Options.off | |empty, repeat= Options && Options.repeat | |empty, ING, RI= 1; if(typeofoptions = = = "function") {off=options; } varf =function () { "Use Strick"if(ing) {repeat (RI++); return; } if(On ()) {ing=false; return; } varR = lockf.apply ( This, arguments); if(typeofr = = "Undefined") {ing=true; } Else{ing= !!R; } }; F.unlock=function() {ing=false; off.apply (arguments); }; returnF; } })();
How to use:
var functionname = lockable (function() { ///needs long time. 111);
Or:
function fn () { if(lockable ()) { return; } // needs long time Fn.unlock ();}
SetInterval (FN, 111);
Lockable JS function, cannot repeat operation before unlocking operation