getter and setter inheritance
lhansen at adobe.com
Mon May 12 08:52:28 PDT 2008
The generated getter and setter ought to have roughly the same
behavior as the getting and setting behavior for a property on
The behavior for reading and writing properties is this, IIRC:
If the class is compiled in standard mode, then reads from nonexistent
properties return undefined. Writes to nonexistent properties
on non-dynamic classes fail silently, whereas writes to nonexistent
properties on dynamic classes create those properties.
If the class is compiled in strict mode, then reads from nonexistent
properties on non-dynamic classes throw an exception (no such property);
reads from nonexistent properties on dynamic classes return undefined.
Writes to nonexistent properties on non-dynamic classes throw an
exception (no such property), whereas writes to nonexistent properties
on dynamic classes create those properties.
For generated getters and setters (in classes at least), it seems
that matching that behavior, except for property creation, is
roughly right. I'd say that the write ought to be silently ignored
on non-strict classes and that an error should be thrown on strict
And yes, it ought to be possible to invoke the superclass getter,
the syntax is as for accessing a property on a superclass,
"super.p" for the immediate base class or "super(C).p" for classes
higher up the inheritance chain.
> -----Original Message-----
> From: P T Withington [mailto:ptwithy at gmail.com] On Behalf Of
> P T Withington
> Sent: 12. mai 2008 07:59
> To: Lars Hansen
> Cc: Kris Zyp; es3.x-discuss at mozilla.org; es4-discuss Discuss
> Subject: Re: getter and setter inheritance
> On 2008-05-09, at 12:46 EDT, Lars Hansen wrote:
> > (One bike ride and one cup of coffee later.)
> > Clearly there is a difference between class/interface
> inheritance on
> > the one hand and prototype inheritance on the other.
> > In either case I think the introduction of a setter and/or
> a getter in
> > a context introduces definitions for both in that context,
> > a special property that holds a getter/setter pair. A missing
> > getter/setter is generated (that's what ES4 specifies now.) That
> > means that in prototype contexts, if an object has a getter or a
> > setter for a
> > field, the prototype will never be searched for the missing half.
> > In a
> > class context, getters and setters can be overridden
> because the class
> > instance only has the one special property with the getter/setter
> > pair, and the values in that property depend on the class that the
> > instance is an instance of. So different classes have different
> > pairs.
> (I've only been to spin class, but I've had 1 coffee and 2 teas.)
> When "A missing getter/setter is generated", what is its
> functionality? Does it just error?
> Can I call a super getter/setter method (I hope)? What is
> the syntax for that?
More information about the Es4-discuss