class Person{
constructor(){
this.name="liu";
this.age = 12;
}
//这里不需要function 否则报错
getName() {
return this.name;
}
getAge() {
return this.age;
}
setName(name){
this.name = name;
}
setAge(age){
this.age = age;
}
}
export default Person;
使用实例:
testClassClick(){
let person = new Person();
console.log(person.getAge() + ":" + person.getName())
person.setAge(20);
person.setName('345464');
console.log(person.getAge() + ":" + person.getName())
},