Skip to content

Instantly share code, notes, and snippets.

@stasimus
Last active October 30, 2018 14:14
Show Gist options
  • Save stasimus/9e5d4097db4f329564860f72f5de4907 to your computer and use it in GitHub Desktop.
Save stasimus/9e5d4097db4f329564860f72f5de4907 to your computer and use it in GitHub Desktop.
class Parent {
x = 1;
show() {
alert(this.x);
}
}
class Child extends Parent {
x = 2;
}
new Child().show(); // shows 2
class MyClass {
x = 1;
show() {
alert(this.x);
}
}
class MyClass {
constructor() {
super();
this.x = 1;
}
show() {
alert(this.x);
}
}
class Parent {
y = 1;
z = 2;
get x() {
return this.y + this.z;
};
show() {
alert(this.x);
}
}
class Child extends Parent {
x = 2;
}
new Parent().show(); // shows 3 as expected
new Child().show(); // shows 3, but 2 is expected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment