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

前端 未结 2 680
灰色年华
灰色年华 2020-12-05 12:24

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 i

相关标签:
2条回答
  • 2020-12-05 12:48

    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

    0 讨论(0)
  • 2020-12-05 12:54

    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).

    0 讨论(0)
提交回复
热议问题