-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Open
Description
There are several occurrences of this particular functionality, so I'd like to propose adding the following utility function.
If you do a search for getWindow().setTimeout
you will see that this function is appropriate for the majority of cases that window.setTimeout
is used.
It is fairly self-explanatory:
/**
* @param {number} delay
* @param {function} callback
* @param {function} elseCallback (optional)
* @returns { any }
*/
function doOrDelay(callback, delay, elseCallback) {
if (delay && delay > 0) {
return getWindow().setTimeout(callback, delay);
} else if (elseCallback) {
return elseCallback();
} else {
return callback();
}
}
Metadata
Metadata
Assignees
Labels
No labels