'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);
本文介绍了一个使用JavaScript编写的Student类,展示了如何通过构造函数初始化对象属性,并使用set和get方法来修改和访问这些属性。实例化过程及属性访问被详细记录。

被折叠的 条评论
为什么被折叠?



