定义get/set方法,用于获取或者修改类的属性
class stu {
constructor(name) {
this.name = name;
}
get() {
return this.name;
}
set(newStr) {
this.name = newStr;
}
}
let xiaoming = new stu("小明");
console.log(xiaoming.get());
xiaoming.set("大明")
console.log(xiaoming.get());
小明
大明
class stu {
constructor(name) {
this.name = name;
}
say() {
return this.name + '说奥里给';
}
}
let xiaoming = new stu("小明");
console.log(xiaoming.say());
小明说奥里给