Node.js中使用计时器定时执行函数详解
如果你熟悉客户端JavaScript编程,你可能使用过setTimeout和setInterval函数,这两个函数允许延时一段时间再运行函数。比如下面的代码,一旦被加载到Web页面,1秒后会在页面文档后追加“Hellothere”:
varoneSecond=1000*1;//onesecond=1000x1ms
setTimeout(function(){
document.write('<p>Hellothere.</p>');
},oneSecond);