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()
posted @ 2020-12-03 15:40  小蓉儿  阅读(101)  评论(0编辑  收藏  举报