setTimeout():如果 EcmaScript 规范中没有定义,我在哪里可以了解它是如何工作的?
我有 另一个关于 setTimeout() 的问题 ,其中用户提到如果函数参数是一个字符串,它将在全局范围内进行计算,否则就不会。这令人大开眼界,所以我试图找到有关 setTimeout 实际工作原理的更多信息,但它不是 EcmaScript 规范的一部分,甚至 MDN 也没有我在 SO 中找到的特定信息。
关于 setTimeout()
如何工作有一些好的参考吗?
I had another question in SO about setTimeout(), where a user mentioned that if the function argument is a string it gets evaluated in global scope, other wise it's not. This was an eye-opener, so I tried to find more info about how setTimeout actually works, but it's not part of the EcmaScript spec and not even MDN had that specific of of information I found in SO.
Is there some good reference about how setTimeout()
works?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
setTimeout
等不在 ECMAScript 规范中,因为它们不是 JavaScript 功能。它们是浏览器环境的window
对象的功能。其他环境(Windows Scripting Host、NodeJS 等)不一定具有这些功能。W3C 一直在尝试标准化
window
对象及其各种功能(包括setTimeout
),最新内容位于 HTML5 规范的计时器部分。其中很多都是对浏览器已经做的事情进行了编纂,尽管其中一些(比如最小间隔值必须是4
[毫秒])似乎(对我来说)是不合适的API 规范和实现似乎有自己的决定(在测试中,您可以看到当前的浏览器很高兴地做更短的间隔,与Opera 显然是个例外,它似乎按照规范进行操作)。setTimeout
and such aren't in the ECMAScript specification because they're not JavaScript features. They're features of the browser environment'swindow
object. Other environments (Windows Scripting Host, NodeJS, etc.) won't necessarily have those features.The W3C has been trying to standardize the
window
object and its various features (includingsetTimeout
), the latest is in the timers section of the HTML5 spec. A lot of it is codifying what browsers already do, although some of it (like saying that the minimum interval value must be4
[milliseconds]) seems (to me) to be out-of-place for an API specification and implementations seem to make up their own minds (in tests, you can see current browsers happily doing a shorter interval, with the apparent exception of Opera which appears to do what the spec says).setTimeout()
方法是window
对象上的一个方法。您可以在下面找到 MDN 文档的链接:https://developer.mozilla.org/ /DOM/window.setTimeout
The
setTimeout()
method is a method on thewindow
object. You can find the link to the MDN documentation below:https://developer.mozilla.org/en/DOM/window.setTimeout