class Person {
// 声明
//公有属性
name;
gf
//私有属性
#age;
#weight;
#bf
//构造方法
constructor(name, age, weight) {
this.name = name;
this.#age = age;
this.#weight = weight;
this.#bf='lijongsuk'
this.gf='yoone'
}
//普通方法
intro() {
console.log(this.name);
console.log(this.#age);
console.log(this.#weight);
}
}
//实例化
const girl = new Person("小可爱", 18, "45kg");
console.log(girl.gf) //yoone
console.log(girl.bf) //访问不了 undefined
girl.intro();
js Class私有属性
最新推荐文章于 2024-04-26 16:47:03 发布