Harmony classes [Was: Operator overloading revisited]

Brendan Eich brendan at mozilla.com
Mon Jul 27 07:44:22 PDT 2009


On Jul 27, 2009, at 2:56 AM, Tom Van Cutsem wrote:

>  Could you point me to a page that explains the rationale behind  
> distinguishing data properties from accessor properties? At first  
> sight, it appears you don't need both since accessor properties can  
> easily subsume data properties.

ES5 is a draft standard based on de-facto standards in JavaScript  
implementations. Accessor properties, commonly called "getters and  
setters", originated almost ten years ago in Mozilla's SpiderMonkey JS  
engine. They were reverse-engineered into other engines more recently.

JS, originally in Netscape 2 in 1995, and in ECMA-262 editions 1  
through 3 (the last edition before ES5, finalized in 1999), had only  
data properties, with class-wise [[Get]] and [[Put]] meta-methods in  
the spec but not exposed to programmers.

My inspirations for JS back in 1995 included Scheme and Self, neither  
of which subsumes anything like data properties under accessor  
properties. What's more, I didn't have time in the early days to  
support user-defined accessors, although native ones existed under the  
hood in custom objects defined by the implementation (i.e., "the  
DOM"). Thus the ES1-3 standards do not describe properties as pairs of  
accessor functions, or talk about exposing such functions to  
programmers and allowing custom getters and setters to be defined.

Since accessors came later, they are observable. You can tell they're  
there using the ES5 meta-programming APIs. They differ from data  
properties in other ways; e.g., you can't shadow an accessor property  
in a prototype object by assignment. Thus ES5 can't easily or  
profitably recast all properties as accessor properties. There would  
still be "data properties" even if the spec formalized on top of  
accessors.

/be
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20090727/b3ad25c9/attachment.html>


More information about the es-discuss mailing list