instance method Function#delay

View source on GitHub →

Function#delay(timeout[, args...]) → Number
  • timeout (Number) – The time, in seconds, to wait before calling the function.
  • args (?) – Optional arguments to pass to the function when calling it.

Schedules the function to run after the specified amount of time, passing any arguments given.

Behaves much like window.setTimeout, but the timeout is in seconds rather than milliseconds. Returns an integer ID that can be used to clear the timeout with window.clearTimeout before it runs.

To schedule a function to run as soon as the interpreter is idle, use Function#defer.

function showMsg(msg) {
showMsg.delay(0.1, "Hi there!");
// -> Waits a 10th of a second, then alerts "Hi there!"