Resolves the following issues:
1 implementing parameters and changing scopes
2 Guaranteed timing trigger, trigger interval.
Call Mode:
1 Method: The methods to be executed use a parameter of paramters [parameter 1, parameter 2]
Paramters: Passed parameters, form [parameter 1, parameter 2]
Milliseconds: Execution interval 1000 for 1 seconds
Scope: Represents a scope
GLOBAL. Timer.setinterval(method, Paramters, Milliseconds,scope);
GLOBAL. Timer.settimeout(method, parameters, Milliseconds,scope);
1Global.namespace ("Timer");2GLOBAL. Timer._calltimeoutmethod =function(method, Parameters,scope) {3 return function() {4 if(typeof(parameters) = = "Undefined" | |typeof(parameters) = = "Null") {5 if(typeof(scope) = = "Undefined" | |typeof(scope) = = "Null")6 {7 method ();8}Else9 {Ten method.apply (scope); One } A}Else { - if(typeof(scope) = = "Undefined" | |typeof(scope) = = "Null") - { the method (parameters); -}Else - { - method.apply (scope,parameters); + } - } + } A }; atGLOBAL. Timer._callintervalmethod =function(method, parameters, Milliseconds,scope) { - return function() { - if(typeof(parameters) = = "Null") { - if(typeof(scope) = = "Undefined" | |typeof(scope) = = "Null") - { - method ();} in Else - { to method.apply (scope); + } -}Else { the if(typeof(scope) = = "Undefined" | |typeof(scope) = = "Null") * { $ method (parameters);}Panax Notoginseng Else - { the method.apply (scope,parameters); + } A } the window.settimeout (Arguments.callee, milliseconds); + } - }; $ /** $ * Call function parameter method requires an array as a parameter - */ -GLOBAL. Timer.settimeout =function(method, parameters, Milliseconds,scope) { the if(typeof(parameters) = = "Null") { - if(typeof(scope) = = "Undefined")Wuyi { the returnWindow.settimeout (GLOBAL. Timer._calltimeoutmethod (method), - milliseconds); Wu}Else - { About returnWindow.settimeout (GLOBAL. Timer._calltimeoutmethod (method,NULL, scope), $ milliseconds); - } -}Else { - if(typeof(scope) = = "Undefined") A { + returnWindow.settimeout (GLOBAL. Timer._calltimeoutmethod (method, the parameters), milliseconds); -}Else $ { the returnWindow.settimeout (GLOBAL. Timer._calltimeoutmethod (method, the parameters,scope), milliseconds); the } the } - }; in theGLOBAL. Timer.cleartimeout =function(Timerid) { the returnwindow.cleartimeout (Timerid); About }; theGLOBAL. Timer.clearinterval =function(timerintervalid) { the returnGLOBAL. Timer.cleartimeout (timerintervalid); the }; + /** - * Secure interval execution with settimeout implementation the */BayiGLOBAL. Timer.setinterval =function(method, Paramters, Milliseconds,scope) { the if(typeof(parameters) = = "Null") { the if(typeof(scope) = = "Undefined") - { - returnWindow.settimeout (GLOBAL. Timer._callintervalmethod (method,NULL, the milliseconds), milliseconds); the}Else the { the returnWindow.settimeout (GLOBAL. Timer._callintervalmethod (method,NULL, - milliseconds,scope), milliseconds); the } the}Else { the if(typeof(scope) = = "Undefined")94 { the returnWindow.settimeout (GLOBAL. Timer._callintervalmethod (method, the parameters, milliseconds), milliseconds); the}Else98 { About returnWindow.settimeout (GLOBAL. Timer._callintervalmethod (method,NULL, - milliseconds,scope), milliseconds);101 }102 }103};
JavaScript-Implemented Timers