Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

setTimeout is not part of the DOM #72

Closed
simevidas opened this Issue · 13 comments

5 participants

@simevidas

The side-note in the chapter about setTimeout is not correct. Quote: "Note: Timeouts are not part of the ECMAScript Standard. They are implemented as part of the DOM."

The setTimeout function and the DOM are not related. The setTimeout function is a global function in the browsers. The DOM is rooted in the document object. Therefore, the timer functions are not part of the DOM in any way.

The note should read: "They are implemented in browsers as global functions (properties of the widow object)."

@oozcitak

The root of the DOM is not the document object, it is the window object. document is actually a property of the window object. (along with other properties such as location, history, etc.)

@simevidas

I disagree. Do you have a source? If you do, please give it.

The DOM specs (the W3C DOM standards) do not mention the window object. The topmost entity defined by the DOM specs is the Document interface. In the browsers, this interface is implemented by the document object. Therefore, the document object is the root of the DOM in the browser.

The browsers implement lots of other global properties (besides the document object). For instance: location, history, navigator, applicationCache, localStorage and sessionStorage, console, the timer functions, alert, postMessage, getSelection, etc. All those properties are NOT considered as part of the DOM.

@simevidas simevidas closed this
@simevidas

I accidentally closed this issue (I'm new to Github). Please re-open.

@ZhangYiJiang ZhangYiJiang reopened this
@oozcitak

After reading the specs once more, I concur. I always assumed the window object was at the top of the DOM hierarchy (think event bubbling), but it appears that it is just part of an optional interface.

@ZhangYiJiang
Collaborator

For what its worth, MDN claims window.setTImeout is part of DOM Level 0. I've also heard of it classified under the Browser Object Model, whatever that is (this SO question does nothing to clear it up).

@simevidas

I've added my answer to that SO question.

@timruffles
Collaborator

It's not part of Javascript the language - it's part of the Javascript environment in the browser (& node). But you're right it's not part of the DOM standard either.

If you fancy updating the wording to be more specific that'd be great! Otherwise I'll close in a few days.

@timruffles timruffles closed this
@kiding

Even to this day, I think the sentence is misleading. "They are being standardized in HTML5" maybe?

Since it's not in ECMAScript standard, node.js has its own implementation; it doesn't return a number ID from setTimeout/setInterval but rather an object. HTML5 states setTimeout should accept parameters that can be delivered to the given function, but IE currently implements it differently, although this difference is not mentioned in the article.

So I think my proposal does imply that they might not work reliably on some JavaScript platforms, also that they might work differently depending on browsers. What do you think?

@timruffles
Collaborator

Pull requests definitely accepted - with some context. Perhaps as a footnote?

@kiding

I'm not sure how to write a footnote since I can't find any example in the article. If we were to write also the context in the Note: section we're talking about, it might be a bit long. Will that be okay? 5 lines tops, I guess.

@kiding

So I've made a pull request referencing this issue. Any comment is appreciated. Thanks!

@timruffles
Collaborator

great - merged it! thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.