我知道使用setTimeout的正确方法如下:
setTimeout(function(){alert('hi!');}, 3000);
或在外部定义函数,然后传递引用:
var foo=function(){alert('hi!');}
setTimeout(foo, 3000);
如果我将其写为:
setTimeout(alert('hi!'), 3000);
看来alert('hi!')
已正确执行。
alert("hi")
立即执行,其结果undefined
传递给setTimeout
...
现在,如果您只是想在指定参数时避免使用包装器,请尝试以下操作:
setTimeout(alert, 3000, "hi!");
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句