Class: Timer

chronoman~ Timer

new Timer(initValue)

Utility class to simplify use of timers created by setTimeout.
Parameters:
Name Type Argument Description
initValue Object <optional>
Specifies initial property values. Keys are property names, their values are values of corresponding properties. The following keys (properties) can be specified:
Name Type Description
action Function Related action that should be executed after time period is elapsed.
active Boolean Whether timer usage should be immediately started.
passToAction Boolean Whether the timer instance should be passed into action function when the function is called.
period Integer Time period in milliseconds that is used to schedule related action execution.
recurrent Boolean Whether related action should be executed repeatedly.
Source:

Members

<protected> _action :Function

Related action that should be executed after time period is elapsed.
The timer instance to which the action is associated will be passed as function's parameter.
Type:
  • Function
Source:
See:

<protected> _active :boolean

Indicates whether timer is in use.
Type:
  • boolean
Source:
See:

<protected> _passToAction :boolean

Indicates whether the timer instance (this) should be passed into action function when the function is called.
Type:
  • boolean
Source:
See:

<protected> _period :integer

Time period in milliseconds. A related action will be executed when the period is elapsed.
Type:
  • integer
Source:
See:

<protected> _recurrent :boolean

Indicates whether related action should be executed repeatedly.
Type:
  • boolean
Source:
See:

<protected> _timeoutId :integer

Timer id.
Type:
  • integer
Source:
See:

Methods

<protected> _clearTimeout() → {Object}

Cancel execution of scheduled action.
Source:
See:
Returns:
Reference to this object.
Type
Object

<protected> _onTimeoutEnd()

Handle timeout's end.
Source:
See:

<protected> _setTimeout() → {Object}

Schedule related action execution.
Source:
See:
Returns:
Reference to this object.
Type
Object

dispose()

Free resources that are allocated for object.
Source:

execute() → {Object}

Execute related action (function). Schedules next execution if action should be executed repeatedly.
The timer instance to which the action is associated will be passed as function's parameter if passToAction property is set to true.
Source:
See:
Returns:
Reference to this object.
Type
Object

getAction() → {Function}

Return function that represents action.
Source:
See:
Returns:
Function that represents action.
Type
Function

getPeriod() → {Integer}

Return time period that is used to schedule related action execution.
Source:
See:
Returns:
Time period in milliseconds.
Type
Integer

isActive() → {Boolean}

Test whether timer is in use.
Source:
See:
Returns:
true, if timer is in use, otherwise false.
Type
Boolean

isPassToAction() → {Boolean}

Test whether the timer instance should be passed into action function when the function is called.
Source:
See:
Returns:
true, if the timer instance should be passed, otherwise false.
Type
Boolean

isRecurrent() → {Boolean}

Test whether related action should be executed repeatedly.
Source:
See:
Returns:
true, if related action should be executed repeatedly, otherwise false.
Type
Boolean

setAction(action) → {Object}

Set function which represents action that should be executed after time period is elapsed.
Parameters:
Name Type Description
action Function Function that represents action.
Source:
See:
Returns:
Reference to this object.
Type
Object

setActive(bActive) → {Object}

Set or cancel timer usage. Depending of this schedules related action execution or cancels action execution.
Consecutive calling with bActive = true leads to related action execution delaying.
Parameters:
Name Type Description
bActive Boolean true to schedule related action execution, false to cancel action execution.
Source:
See:
Returns:
Reference to this object.
Type
Object

setPassToAction(bPass) → {Object}

Set or cancel passing of timer instance into action function.
Parameters:
Name Type Description
bPass Boolean true, if the timer instance should be passed into action function, false, if the instance should not be passed.
Source:
See:
Returns:
Reference to this object.
Type
Object

setPeriod(nPeriod) → {Object}

Set time period that is used to schedule related action execution.
Parameters:
Name Type Description
nPeriod Integer Time period in milliseconds.
Source:
See:
Returns:
Reference to this object.
Type
Object

setRecurrent(bRecurrent) → {Object}

Set or cancel repeating of related action execution.
Parameters:
Name Type Description
bRecurrent Boolean true, if action should be executed repeatedly, false, if action repeating should be off.
Source:
See:
Returns:
Reference to this object.
Type
Object

start(nPeriod) → {Object}

Start timer usage (make it active).
Parameters:
Name Type Argument Description
nPeriod Integer <optional>
Time period in milliseconds that is used to schedule related action execution (new value for period property). The current value of period property is used by default.
Source:
See:
Returns:
Reference to this object.
Type
Object

stop() → {Object}

Stop timer usage (make it inactive).
Source:
See:
Returns:
Reference to this object.
Type
Object

toString()

Convert object into string.
Source: