Method Function.defer
Defer execution of a function.
-
Syntax
undefined Function.defer(Number n , Object obj , [ Mixed a2...an ])
This method will defer execution of the functionnmilliseconds. If an objectobjis provided then the function will be executed as a method on the object.
Any extra argumentsa2...anwill be passed along to the function.
Note that it is not possible to retrieve the return value from a defered function. -
Parameters
Number n- Number of milliseconds.
Object obj- The object which should invoke the function as a method. If
nullthe the function is executed normally. Mixed a2...an(Optional)- Addtional arguments are passed along to the function.
-
Return value
No explicit return value. Default value of
undefinedis returned. -
Examples
- To defer a function 1 second passing a single argument to the function
// Define a function which alerts the first argument var f = function(){alert(arguments[0]);}; // Defer execution 1 second passing the string 'JSLab' f.defer(1000,null,'JSLab'); // Output is 'JSLab'- To defer a method 4 seconds
// Define an object var o = {}; // Define a method o.m = function(){alert(this.constructor);}; // Defer execution of method 4 seconds o.m.defer(4000,o); // Output is 'Object...'
-
Download
Source
Unless otherwise noted all code in the JSLab Standard Library is licensed as GPLv3. See http://www.gnu.org/licenses/gpl.html for the entire license.
