tern
tern copied to clipboard
Extended classes do not inherit parent member variables.
Objects created from a class do have all variables defined in the constructor and inside other member functions. When you extend that class, objects created from the extended class do not inherit parent member variables, only functions and getters. The parent variables aren't visible inside the extended class functions too.
-Test case 1:
test2 is a Core2 object that extends Core, var1 from Core is not visible
-Test case 2 (Expected behaviour):
test1 is a Core object, var1 from Core is visible
-Test case 3:
Inside the constructor of Core2, var1 from Core is not visible
Here's the code for testing:
class Core {
constructor() {
this.var1 = 1;
}
get var2() {
return 2;
}
}
class Core2 extends Core { }
const test1 = new Core();
const test2 = new Core2();
test2.
Many thanks!
Can't reproduce case 3

Case 1 is incorrect because it requires super()
in the consturctor of Core2
Case 2 is expected behavior
I found out that Case 3 was a typo in the constructor, sorry! So, as for the first case, I assume that the declaration of the constructor and super()
are mandatory for the engine to recognize parent's variables? If I'm not mistaken, when the constructor is not declared, the parent constructor is called automatically.
Yes, but it not easy to do something when not see something. I will keep this open until I found a good solution.