classPerson{constructor(name){this.name = name;}getname(){return"我叫: "+this._name
}setname(val){if(typeof val !=="string"){thrownewTypeError("get error type of value: \"name\" ")}this._name = val
}}const a =newPerson("张三");
console.log(a.name);//"我叫: 张三"
静态成员
classTest{static a =10;staticsay(){
console.log("123");}}let demo =newTest();
console.log(demo.a);//undefined
console.log(Test.a);// 10
demo.say();//demo.say is not a function
Test.say();//"123"
字段初始化器
classTest{
a =10;
b =20;}let demo =newTest();
demo.a;//10
demo.b;//20