There seems to be tentative agreement to remove the private field shorthand given the added confusion and edge cases involved with the shorthand. Refs: https://github.com/tc39/proposal-class-fields/issues/21
40 lines
783 B
JavaScript
40 lines
783 B
JavaScript
class Point {
|
|
#x = 1;
|
|
#y = 2;
|
|
|
|
constructor(x = 0, y = 0) {
|
|
this.#x = +x;
|
|
this.#y = +y;
|
|
|
|
this.foo = class {
|
|
#x = 1;
|
|
#y = 2;
|
|
|
|
constructor(x = 0, y = 0) {
|
|
this.#x = +x;
|
|
this.#y = +y;
|
|
}
|
|
|
|
get x() { return this.#x }
|
|
set x(value) { this.#x = +value }
|
|
|
|
get y() { return this.#y }
|
|
set y(value) { this.#y = +value }
|
|
|
|
equals(p) { return this.#x === p.#x && this.#y === p.#y }
|
|
|
|
toString() { return `Point<${ this.#x },${ this.#y }>` }
|
|
};
|
|
}
|
|
|
|
get x() { return this.#x }
|
|
set x(value) { this.#x = +value }
|
|
|
|
get y() { return this.#y }
|
|
set y(value) { this.#y = +value }
|
|
|
|
equals(p) { return this.#x === p.#x && this.#y === p.#y }
|
|
|
|
toString() { return `Point<${ this.#x },${ this.#y }>` }
|
|
}
|