码迷,mamicode.com
首页 > Web开发 > 详细

setTimeout函数在浏览器中和Node.js中的区别

时间:2015-07-14 05:58:08      阅读:283      评论:0      收藏:0      [点我收藏+]

标签:

setTimeout函数delay时间之后执行一次func.

setTimeout函数原型:

var timeoutID = window.setTimeout(func, [delay, param1, param2, ...]);
var timeoutID = window.setTimeout(code, [delay]);//not recommended for the same reasons as using eval()

//param1, param2, and so forth are additional parameters which are passed through to the function specified by func.

 

区别:

  • 浏览器中:func参数为函数对应的字符串
  • Node.js中:func参数为函数名
//In Broswer
function f(){
    alert("H");
}
function f2(){
    setTimeout("f()", 2000);
}
window.onload = f2;

//In Node.js
function f(){
    console.log("H");
}
function f2(){
    setTimeout(f, 2000);
}
f2();

 

setTimeout函数在浏览器中和Node.js中的区别

标签:

原文地址:http://www.cnblogs.com/bukekangli/p/4644303.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!