直接跑一下这段代码及注释,看下控制台的输出
class Person {
constructor(name, age) {
this.name = name;
this.age = age;
}
say() {
return '我的名字是' + this.name;
}
set birth(value) {
this._birth = `${value}-`;
}
get birth() {
return this._birth;
}
}
class Animal extends Person {
constructor(name, age) {
super(name, age)
this.age1 = age
}
say() {
return 'My name is' + this.name;
}
}
const animal = new Animal('嘻嘻', 5);
const person = new Person('哈哈', 11);
console.log('animal', animal);
console.log('person', person);
person.birth = 123;
console.log('birth', person.birth);
console.log('birth', person.say);
console.log('birth', animal.say);