Last active
October 30, 2018 14:14
-
-
Save stasimus/9e5d4097db4f329564860f72f5de4907 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Parent { | |
x = 1; | |
show() { | |
alert(this.x); | |
} | |
} | |
class Child extends Parent { | |
x = 2; | |
} | |
new Child().show(); // shows 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyClass { | |
x = 1; | |
show() { | |
alert(this.x); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyClass { | |
constructor() { | |
super(); | |
this.x = 1; | |
} | |
show() { | |
alert(this.x); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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