setTimeout("doSomething(var1)",10000);
但是,我也有var1作为全局变量. 10000毫秒后,它会调用本地var1还是全局var1?
setTimeout('doSomething(var1)',10000);
将传递全局变量var1,
还有这个:
setTimeout(function() { doSomething(var1); },10000);
将传递局部变量var1.
现场演示:http://jsfiddle.net/simevidas/EQMaz/