setTimeout():如果 EcmaScript 规范中没有定义,我在哪里可以了解它是如何工作的?

发布于 2024-12-27 00:31:19 字数 361 浏览 0 评论 0原文

我有 另一个关于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笑咖 2025-01-03 00:31:19

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's window 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 (including setTimeout), 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 be 4 [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).

旧街凉风 2025-01-03 00:31:19

setTimeout() 方法是 window 对象上的一个方法。您可以在下面找到 MDN 文档的链接:

https://developer.mozilla.org/ /DOM/window.setTimeout

The setTimeout() method is a method on the window object. You can find the link to the MDN documentation below:

https://developer.mozilla.org/en/DOM/window.setTimeout

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文