Static method inheritance
Yes, they are: by method definitions for constructor() and then to FunctionCreate, which goes to FunctionAllocate which sets the [[Prototype]] to passed superclass in case of extends.
(sorry my previous explanation was unclear, and you need to double-check it here)
Dmitry
On Jul 5, 2013, at 5:27 PM, Jeff Morrison wrote:
I'm reading through the spec and trying to understand whether static methods on harmony classes are inherited by their subclasses or not, and as far as I can tell they are not -- is this correct?
Yes, they are inherited as properties of subclass constructors.
In the ES6 spec. see section 13.5, Runtime semantics, Cl;assDefinitionEvaluation for production ClassTail : ClassHeritage { ClassBody}
Lines 2.g.iv which is Let constructorParent be superclass.
Line 9 passes constructorParent as the functionPrototype argument for Property DefinitionEvaluation of the constructor.
I see that the harmony class wiki suggests this topic is an open issue -- but the maximally-minimal wiki says nothing explicit about it.
That Wiki page starts with "This proposal has progressed to the Draft ECMAScript 6 Specification..." which basically means read what the spec. says, the wiki pages generally don't get updated and are kept around for ground.
On 7/5/13 9:53 PM, Allen Wirfs-Brock wrote:
On Jul 5, 2013, at 5:27 PM, Jeff Morrison wrote:
I'm reading through the spec and trying to understand whether static methods on harmony classes are inherited by their subclasses or not, and as far as I can tell they are not -- is this correct? Yes, they are inherited as properties of subclass constructors.
In the ES6 spec. see section 13.5, Runtime semantics, Cl;assDefinitionEvaluation for production ClassTail : ClassHeritage { ClassBody}
Lines 2.g.iv which is Let constructorParent be superclass.
Line 9 passes constructorParent as the functionPrototype argument for Property DefinitionEvaluation of the constructor.
Right but the definition of Property Definition Evaluation appears to say the following:
If ReferencesSuper of MethodDefinition is true, then a. Let closure be the result of performing the FunctionCreate abstract operation with arguments Method, StrictFormalParameters, FunctionBody, scope, and strict and with object as the homeObject optional argument and propName as the methodName optional argument. If functionPrototype was passed as a parameter then also pass its value as the functionPrototype optional argument of FunctionCreate.
And, reading the definition of FunctionCreate, it seemed like that would
just mean that the prototype of the function is set to [effectively]
functionPrototype || %FunctionPrototype%
-- but properties of a
function object do not sit on the prototype, they sit on the object
directly. Am I missing something here?
Ah wait I see -- it's not that the prototype property is set to superClass, it's that the actual prototype of the function object is set to the superClass object. Ok cool makes sense, thanks for the clarification guys!
On Jul 5, 2013, at 11:53 PM, Jeff Morrison wrote:
Ah wait I see -- it's not that the prototype property is set to superClass, it's that the actual prototype of the function object is set to the superClass object. Ok cool makes sense, thanks for the clarification guys!
Yes, and that's what I meant by "long story short":
F.[[Prototype]] = constructorParent F.prototype = Object.create(protoParent)
Dmitry
P.S.: (the actual prototype is always the [[Prototype]] internal property, and it goes form ES3 and earlier specs; the "prototype" explicit property on the constructor is just the explicit reference to the prototype of of instances)
I'm reading through the spec and trying to understand whether static methods on harmony classes are inherited by their subclasses or not, and as far as I can tell they are not -- is this correct? I see that the harmony class wiki suggests this topic is an open issue -- but the maximally-minimal wiki says nothing explicit about it.
Thanks in advance!