What functions’s [[Prototype]]
points to?
In the below code, constructor function b
‘s [[Prototype]]
points to constructor function a
.
class a{}
class b extends a{}
Object.getPrototypeOf(b)===a //true
What functions’s [[Prototype]]
points to?
In the below code, constructor function b
‘s [[Prototype]]
points to constructor function a
.
class a{}
class b extends a{}
Object.getPrototypeOf(b)===a //true
2
Answers
Right, that’s how
class
syntax works. It sets up two parallel lines of inheritance:The prototype of function
b
is functiona
(which is how it inherits static methods). That’s covered by the specification’s abstract ClassDefinitionEvaluation operation (the function inheritance part is step 8(h)(iii) as of this writing) and the parts of the spec that call it.The prototype of an ordinary function is
Function.prototype
(see InstantiateOrdinaryFunctionObject). Generator functions,async
functions, andasync
generator functions inherit from prototypes that aren’t directly exposed by a built-in property (1, 2, 3).The
[[Prototype]]
ofclass B
isclass A
This is how
static
inheritance work – statics missing onclass B
are taken from its[[Prototype]]
,class A
The
.prototype
ofclass B
is an instance ofclass A
with assigned{ constructor: class B }
This is how instance inheritance works – properties missing on
B.prototype
are taken from its[[Prototype]]
,A { [[Prototype]]: A.prototype, constructor: class B }