class Point {
#x;
constructor(coordX) {
this.#x = coordX;
}
get x() {
return this.#x;
}
set x(value) {
if(value >= 0) {
this.#x = value;
}
}
}
Click Run to execute JavaScript.
Code runs in an isolated environment.