(function () { /** * readonly * static * protected 受保护的:只能在当前类的子类中访问 * public 共用的 * private:只能在当前类进行使用和修改 */ class Person { constructor(name, age) { this.name = name; this.age = age; } getName() { return console.log; } get name1() { return this.name; } set name1(val) { this.name = val; } } let newPerSon = new Person('哆啦A梦', 7); newPerSon.name1 = '图图'; console.log(newPerSon); console.log(newPerSon.name1); newPerSon.getName(); })();