Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Timer.jsm

Timer.jsm JavaScript模块包含纯JavaScript对setTimeoutclearTimeoutsetIntervalclearInterval功能的实现且适用于DOM窗口函数,但它还可以被那些无法访问DOM窗口的代码(如JavaScript模块框架里的脚本)使用。

 

要使用Timer.jsm,首先导入它:

Components.utils.import("resource://gre/modules/Timer.jsm");

然后如同在DOM窗口中一样使用setTimeout和clearTimeout,例如:

let timeoutID = setTimeout(function() { console.log("Hello!"); }, 500);

clearTimeout(timeoutID);

类似地,你可以使用setInterval和clearInterval,比如:

let intervalID = setInterval(function() { console.log("Happening every 500ms!"); }, 500);

clearInterval(intervalID);

文档标签和贡献者

 此页面的贡献者: WarriorWu
 最后编辑者: WarriorWu,