Last active
May 1, 2024 21:16
-
-
Save dgeibi/9bb73ba00a90989a56780137879c9563 to your computer and use it in GitHub Desktop.
[ES6 Class]
This file contains hidden or 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 Point { | |
| set X(v) { | |
| this.x = v; | |
| } | |
| get X() { | |
| return this.x; | |
| } | |
| getX() { | |
| console.log(this.X); | |
| } | |
| } | |
| class ColorPoint extends Point { | |
| constructor() { | |
| super(); | |
| super.X = 3; | |
| console.log(this.X) // A | |
| console.log(super.X) // B | |
| } | |
| m() { | |
| this.x = 100; | |
| this.getX(); | |
| } | |
| get X() { | |
| return 1; | |
| } | |
| } | |
| const cp = new ColorPoint(); | |
| cp.m(); | |
| //chrome: 1, 3, 1 |
This file contains hidden or 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
| // from justjavac | |
| class Point { | |
| getX() { | |
| console.log(this.x);// C | |
| } | |
| } | |
| class ColorPoint extends Point { | |
| constructor() { | |
| super(); | |
| this.x = 2; | |
| super.x = 3; | |
| console.log(this.x)// A | |
| console.log(super.x)// B | |
| } | |
| m() { | |
| this.getX() | |
| } | |
| } | |
| const cp = new ColorPoint(); | |
| cp.m(); | |
| // chrome: 3 undefined 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment