简体   繁体   English

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

[英]setTimeout(): If not defined in EcmaScript spec, where can I learn how it works?

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 . 在SO中另一个关于setTimeout()的问题 ,其中一个用户提到如果函数参数是一个字符串,它会在全局范围内进行评估,否则它就不会 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. 这让人大开眼界,所以我试图找到更多关于setTimeout实际工作方式的信息,但它不是EcmaScript规范的一部分,甚至MDN都没有我在SO中找到的那些特定信息。

Is there some good reference about how setTimeout() works? 有关setTimeout()如何工作的一些很好的参考?

setTimeout and such aren't in the ECMAScript specification because they're not JavaScript features. setTimeout等不在ECMAScript规范中,因为它们不是JavaScript特性。 They're features of the browser environment's window object. 它们是浏览器环境的window对象的特征。 Other environments (Windows Scripting Host, NodeJS, etc.) won't necessarily have those features. 其他环境(Windows Scripting Host,NodeJS等)不一定具有这些功能。

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 . W3C一直在尝试标准化window对象及其各种功能(包括setTimeout ), 最新版本在HTML5规范的定时器部分 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). 其中很多都是编码已经做过的浏览器,虽然其中一些(比如说最小间隔值必须是4 [毫秒])似乎(对我而言)对于API规范来说是不合适的,并且实现似乎构成他们自己的想法( 在测试中 ,你可以看到当前的浏览器愉快地做了一个更短的间隔,Opera的明显例外似乎做了规范所说的)。

The setTimeout() method is a method on the window object. setTimeout()方法是window对象上的一个方法。 You can find the link to the MDN documentation below: 您可以在下面找到MDN文档的链接:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM