Skip to content

Instantly share code, notes, and snippets.

@dgeibi
Last active May 1, 2024 21:16
Show Gist options
  • Select an option

  • Save dgeibi/9bb73ba00a90989a56780137879c9563 to your computer and use it in GitHub Desktop.

Select an option

Save dgeibi/9bb73ba00a90989a56780137879c9563 to your computer and use it in GitHub Desktop.
[ES6 Class]
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
// 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