首页 Node.js核心模块手册

参数说明


setTimeout(function, ms, v, ...)

function     回调函数
ms           定时时间,单位毫秒
v, ...       回调函数,参数

返回:定时器ID

示例


function fun(str1, str2){
  console.log( str1 + str2 );
}
var t = setTimeout(fun, 1000, "a", "b");  //1秒后执行

结果:ab


中途需要终止定时使用:
clearTimeout( t );

使用nodejs新增定义函数:
t.unref();      //终止定时
t.ref();        //恢复定时