[英]Javascript setTimeout sequence
Say I have this line of javascript- 说我有这行javascript-
setTimeout(function() { console.log("okay"); }, 5000);
/* Blah blah- more code */
Is that going to wait 5 seconds, run the console.log()
, then continue on the the rest of the script? 那会等待5秒钟,运行console.log()
,然后继续执行脚本的其余部分吗?
OR 要么
Is it going to set the console.log()
to be ran in 5 seconds while its already went ahead and is running the rest of the code? 是否要将console.log()
设置为在5秒钟内已经运行并且正在运行其余代码的情况下运行?
setTimeout()
will set the console.log()
to be run in 5 seconds and continue running the remaining code immediately. setTimeout()
会将console.log()
设置为在5秒钟内运行,并立即继续运行其余代码。
In other words, setTimeout()
calls it's target code asynchronously. 换句话说, setTimeout()
异步调用它的目标代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.