Timer
NOTE: The initial APIs of this module are supported since API version 4. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Module to Import
None
Required Permissions
None
setTimeout
setTimeout(handler[,delay[, ...args]]): number
Sets a timer for the system to call a function after the timer goes off.
-
Parameters
-
Return Value
-
Example
export default { setTimeOut() { var timeoutID = setTimeout(function() { console.log('delay 1s'); }, 1000); } }
clearTimeout
clearTimeout(timeoutID: number): void
Cancels the timer created via setTimeout().
-
Parameter
ID of the timer to cancel, which is returned by setTimeout()
-
Example
export default { clearTimeOut() { var timeoutID = setTimeout(function() { console.log('do after 1s delay.'); }, 1000); clearTimeout(timeoutID); } }
setInterval
setInterval(handler[, delay[, ...args]]): number
Sets a repeating timer for the system to repeatedly call a function at a fixed interval.
-
Parameters
Additional parameter to pass to the handler after the timer goes off
-
Return Value
-
Example
export default { setInterval() { var intervalID = setInterval(function() { console.log('do very 1s.'); }, 1000); } }
clearInterval
clearInterval(intervalID: number): void
Cancels the repeating timer set via setInterval().