定时器(JavaScript)

NativeScript 的全局 timer 变量允许你为异步延迟函数调用设置超时和间隔。

输入

var timer = require("timer")

超时

var callback = function(){
    console.log("I will be executed once after 500ms");
}
var timeoutId = timer.setTimeout(callback, 500);

// clearing the timeout
timer.clearTimeout(timeoutId);

间隔

var callback = function(){
    console.log("I will be executed every 500 ms")
}
var intervalId = timer.setInterval(callback, 500);

// clearing the interval
timer.clearInterval(intervalId);