C++:
```c++
#include <iostream>
class A {
public:
A () {
this->x = 1;
}
int call () {
return this->x;
}
int x;
};
class B : public A {
public:
B() : A () {
this->x = 2;
}
int x;
};
int main () {
B b;
std::cout << b.call(); // 1
return 0;
}
```
JavaScript:
```js
class A {
constructor () {
this.x = 1;
}
call () {
return this.x;
}
}
class B extends A {
constructor () {
super();
this.x = 2;
}
}
let b = new B();
b.call(); // 2
```
~~Why we have different behavior?!~~
I know that ECMAScript classes are syntactical sugar, but this behavior is
unexpected for many people...
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss