inheriting statics

P T Withington ptw at
Sun Jan 7 14:11:38 PST 2007

On 2007-01-07, at 15:53 EST, Brendan Eich wrote:

> On Jan 7, 2007, at 12:23 PM, P T Withington wrote:
>>> Inclusion of statics in the scope chain within instance methods  
>>> is a convenience afforded by the new special form of methods  
>>> defined via function definitions nested in a class definition.  
>>> But it's not inheritance.
>> One could still ask, "should _classes_ inherit static properties  
>> of their superclass?"
> Yes, you're right that classes are not functions -- hence  
> f.prototype is an instance property of each function object f, not  
> a static of an (unnamed, varargs-type-parameterized?) Function  
> subclass magically created "backstage" for f's function definition,  
> and f.prototype is not of course the same object as  
> Function.prototype.
> So adding classes creates choice for the designer about static  
> inheritance and scope. I'll defer to Jeff or Ed to speak to the AS3  
> design goals and experience.
>>   Should the statics of my superclass be in my scope chain?
> Define "my".

I my sketch below, should methods of Bar have ZOT in their scope  
chain?  Should I be able to write:

class Bar extends Foo {
   function improvedZotValue() {
     return ZOT + 1;

and have ZOT resolve to Foo.ZOT?

>>   Should statics of an instance's superclass be visible in the  
>> instance's constructor?
>> class Foo {
>>   static const ZOT = 42;
>>   function zotValue() {
>>     return this.constructor.ZOT;
>>   }
>> }
>> class Bar extends Foo {
>>   function improvedZotValue() {
>>     return this.constructor.ZOT + 1;
>>   }
>> }
> Is this use-case important in your experience?  The sketch here  
> does not need to abstract away from Foo or Bar via  
> this.constructor, but perhaps you have an example motivating such  
> abstraction?

My motivation is to keep the door open for a mix-in, where the  
superclass(es) could be different for different concrete classes.   
But it also would make refactoring easier if I could move a static  
property to a different superclass and not have to update all uses of  
it in subclasses.

More information about the Es4-discuss mailing list