‘use strict‘ class Student { constructor(_name,age){ this.name = _name; this.age = age; } set name(_name){ this._name = ‘aaa‘+_name; }; get name(){ return this._name; }; set age(a){ this._age = a; } get age(){ return this._age; } }var ss =new Student(‘yan‘,19);new时候先执行constructor,然后发现this.name然后找到了set 后的name这个方法。console.log(ss);
时间: 2024-12-09 00:37:19