- From: Geoffrey Garen <ggaren@apple.com>
- Date: Fri, 3 Oct 2008 01:40:51 -0700
- To: Maciej Stachowiak <mjs@apple.com>
- Cc: public-webapps@w3.org
>> Pros: >> >> * Fits the object-oriented programming model of "new Image", "new >> XMLHttpRequest", etc. >> >> * Enables use of object-oriented features like instanceof, >> the .constructor property, and prototype-based extensions to timer >> objects. >> >> * Distinguishes itself better from the old setTimeout / setInterval >> functions. > > In general, the DOM does not depend on a constructor as the only way > to create a kind of object, since it is nominally language-agnostic. > In fact, for most things it doesn't provide a constructor invokable > as such at all; you listed some of the few exceptions. A Timer constructor is language-agnostic as long as you specify that "new Timer()" and "Timer()" behave the same way. Other JavaScript constructor APIs, like Array, behave this way. The fact that most things in the DOM aren't instantiated by constructors is really just an accidental consequence of the fact that they're available as properties of the document, and it makes no sense to create them standalone. The two qualities are not found in timers. > In addition, "new Timer(...)" does not as clearly express the fact > that the timer is not only created but started right away. So I > don't think a constructor would be good as the sole interface for > starting a timer. That seems like a minor criticism, relative to the pros above. Besides, we all know that if this API becomes standardized, Mozilla is going to add a global Timer constructor, just like they did for all the other classes in the DOM. And we all know that WebKit will follow suit. So why not get a jump start on things, and specify it that way from the beginning? I guess we could make a Timer constructor that threw when you called it, as we did with node-related DOM constructors, but that behavior is really weird. Geoff
Received on Friday, 3 October 2008 08:41:32 UTC