Now I am not 100% but here is my 2 cents on what is going on
super is acting pretty super weird, from the looks of it appeared as super acts different thing in different operation, and that is exactly what is happening. Suspecting it earlier I tried to console.log(super) and error happened. When I googled to find why? I came across the explanation, along the lines of "its a keyword like var and you cannot log var keyword as it is". So that tells us super is not your regular object.
What happens is when you do some thing like
constructor() {
super();
}
Here super() will actually call the constructor of prototype C, which you can see when you console.log(C) which results into
C = {
constructor: f(),
say: f()
}
But as soon as you do
class D extends C {
constructor(id) {
super();
super.say2 = function() {
console.log('changed ' + this.id);
}
}
Here super.say2 actually refers to this or instance of class D (Holy Mother of Bejesus, how can somebody get away with something like that)
I changed the name to say2 to verify exactly that, see your code below which I changed to test that
class C {
say() {
console.log('hello');
}
}
class D extends C {
constructor(id) {
super();
super.say2 = function() {
console.log('changed ' + this.id);
}
console.log(this)
console.log(D.prototype)
}
shout() {
super.say()
}
}
let d = new D(1)
d.say()
d.shout()
When you run this code what you will see in console is

Here say2 is actually in the instance of D, and where is say of C prototype? well, see for yourself its still there UNCHANGED

So in summary when you call super.say() it calls the function of C prototype, when you do super.say = function() in constructor, it assigns it to current instance of D
At best from further testing what I came to know is super is evaluated as something called intermedia.value because when I did this
shout() {
super.say2()
}
It gave error Uncaught TypeError: (intermediate value).say2 is not a function
Summary
- When you called
d.say() It actually referred to say function of
instance d
- When you called
d.shout() It referred to say method of class C
God, just when I thought I know JS