Last active: 2 years ago
class Person {
#age = 0;
constructor(name, age) {
this.name = name;
this.#age = age;
Object.defineProperty(this, 'name', { enumerable: false });
Object.defineProperties(this, {
name: {
enumerable: false,
},
age: {
enumerable: true,
},
});
}
get age() {
return this.#age;
}
}
const xfy = new Person('xfy', 18);
console.log(xfy.name);
console.log(xfy.age);
console.log(xfy);