定時器(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);