I decided to actually check the ECMAScript 3.1 draft. If you thought HTML5 was horrible, ECMAScript 3.1 is a ~3.2MiB PDF file downloadable from a wiki page. No live updates, no inline links, no chapter links, mu. Anyways, a colleague told me getters and setters were defined in section 11.1.5 so I looked there (January 12 draft). It states
set are the keywords to be used, as in the first example of my last post. So some part of the de facto getters and setters support survives. Hurray!
__defineGetter__ and friends are not defined at all in the draft though which seems to indicate that TC39 takes a different approach to things than e.g. the HTML WG. The draft however does define a new way to do getters and setters in section 8.10.5 and as far as I can tell that is the one Internet Explorer 8 attempts to implement. I say attempt, as Internet Explorer is using
setter as keywords according to a document on MSDN where the draft states
set are supposed be it.
Thus the question is, did the Microsoft engineers made a typo? Or did TC39 decide on a change the January 12 draft does not reflect?
After some more digging, the changelog in the draft says that December 22 last year the
setter keywords were renamed to
set, citing issue 441, which, as it turns out, is marked invalid. I’m guessing pratapL of TC39 made a mistake in changing it everywhere rather than just in section 11.1.5, though maybe consistency was intentional and Internet Explorer needs to change.
Perhaps the the ECMAScript mailing list could clarify the issue?
From what I gather, pratapL is Pratap Lakshman from VJ#SDK at Microsoft.
Travis clarified the situation in a comment on my previous post. Apparently the MSDN documentation is out of date.
That officially made my day
Here is a hopefully complete explanation:
The keywords used to define getters/setters in the object literal syntax have been
set since early drafts.
At the time issue 441 was closed, and also at the time the MSDN documentation was written, the property names used in descriptor objects passed to
Object.create (and in a few other places) were
setter. They have since been changed to
set (which don't need to be quoted, since the
set used in object literals are only keywords in that context).
Issue 441 was questioning whether the object literal keywords and the
Object.create/defineProperty methods of defining getters and setters should both be supported. They should, because the object literal keywords are more concise and are a de facto standard, while
Object.create/defineProperty are more expressive (since the property names and attributes can be determined programmatically, and after an object is created). So it was correct to close 441 as invalid.
The MSDN documentation uses only descriptor objects, not object literal syntax, so it was correct when it was written (but should be updated, as Travis says).
The MSDN doc suggests that for portability, you should test at run-time whether to use
__defineGetter/Setter__. But using the object literal get/set syntax is simpler and just as portable: it will work or already works in
Falling back to
__defineGetter/Setter__ would I believe only get you additional compatibility with IE8 RC1, and some very old versions of SpiderMonkey. So use the object literal syntax unless you need programmatic selection of names and attributes, or to add getters/setters to existing objects.
TC39 does indeed take a noticeably different approach than HTML WG / WHATWG :-)
The lack of internal links in the PDF is now issue 452; thanks for reminding me of this.
I admire you! Thank you!