inheriting statics

Brendan Eich brendan at
Sun Jan 7 12:53:38 PST 2007

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".

>   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?


More information about the Es4-discuss mailing list