(function () { /*** * 只读 readonly * 类 static * 私有的 private: * 只能在当前类中访问和修改 * 若是想要修改 则需要在类里进行定义方法 * 共有的 public * 受保护的 protected * 只能在当前类及当前类的子类中访问及使用 */ class Person { constructor(name, age) { this.name = name; this.age = age; } /*** * 在属性的封装中 * 修改数据 通过setter => set * 获取数据 通过getter => get */ // name = '啧啧啧' // getName() { // return this.name; // } // setName(a) { // this.name = a; // } get name1() { return this.name; } set name1(b) { this.name = b; } } let p1 = new Person('哪吒', 7); // p1.name = '猪八戒'; console.log(p1.name1); p1.name1 = '唐僧'; console.log(p1.name1); // console.log(p1.name); // console.log(p1.setName("猪八戒")) // console.log(p1.getName()) })();