恰巧code什么history.back()后? [英] What happens to code after history.back()?
问题描述
我有code这样的:
window.history.back();
myFunction(10);
-
是
history.back()
阻塞/非阻塞电话?是否有
myFunction的()
将被执行的保证?或将不会执行?Is there an assurance that
myFunction()
will be executed? or will not be executed?这是一个可能的竞争状态,其中
history.back()
异步发生,
是否myFunction的()
被称为依赖于不可控事件的时机?Is this a possible race condition where
history.back()
happens asynchronously and whethermyFunction()
is called depends on timing of uncontrollable events?推荐答案
实际操作历史code(这是内部的JS实现)的主要的事件循环。您的来电
myFunction的
在本轮执行同步执行,所以它总是顺应环境中执行。The actual history manipulation code (which is internal to the JS implementation) will therefore be executed during the next run of the main event loop. Your call to
myFunction
executes synchronously in the current round of execution, so it will always be executed in compliant environments.然而,只有在
myFunction的
同步code是保证执行。考虑这个例子:However, only synchronous code in
myFunction
is guaranteed to execute. Consider this example:function myFunction() { console.log('synchronous'); debugger setTimeout(function() { console.log('async'); debugger }) } window.history.back(); myFunction();
第一个调试器语句总是击中。第二,这是使用推迟到未来事件循环剔
的setTimeout
,不会的。本文是一个很好的JavaScript的事件循环的解释
This article is a good explanation of the JavaScript event loop
这篇关于恰巧code什么history.back()后?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!