es11私有属性

22 阅读1分钟
class person{
共有属性
name;
私有属性
#age;
#weight;
constructor(name,age,weight){
this.name=name;
this.#age=age;
this.#weight=weight;
}
intro(){
console.log(this.name);
console.log(this.#age);
console.log(this.#weight);
}
}

const girl=new person('小红',18,'45kg');

girl.intro();