PP.setTimeout

Syntax

setTimeout(func: Function, delay: Number, params: Object, context: Object);

Parameters

func. Function called after specified time has elapsed.

delay. Delay in milliseconds.

params. Parameters with which the function should be called.

context. Function context.

Description

The setTimeout method asynchronously calls specified function after selected time has elapsed.

Comments

The method returns ID of the created timer: a Number type value.

Example

To execute the example, add a link to PP.js scenario file to HTML page. Show all odd numbers between 0 and 7 (inclusive) with the delay set to three seconds:

// Function that must be performed in three seconds
function func(args) {
    console.log(args.value);
};
for (var i = 0; i <= 7; i++) {
    // Set the timer that calls the function in three seconds
    var idTimer = PP.setTimeout(func, 3000, {
        value: i
    }, this);
    if (i % 2 == 0) {
        // Stop the time if the cycle counter has even value
        PP.clearTimeout(idTimer);
    };
};

When three seconds after the example execution have elapsed, the browser console displays all odd numbers between 0 through 7 (inclusive):

1
3
5
7

See also:

PP