class Animal {
constructor(name) {
this.name = name;
}
getName() {
return this.name;
}
}
class Dog extends Animal {
constructor(name, age) {
super(name);
this.type = "animal";
this.age = age;
}
}
class Cat {
constructor(age) {
this.age = age;
}
}
let dog = new Dog();
dog.name = "中华田园犬";
dog.age = 5;
let cat = new Cat();
cat.age = 4;
cat.name = "布偶猫";
console.log(333, dog,cat);//{name:'中华田园犬',age:5,type:'animal'} {name:'布偶猫',age:4}
console.log(333,dog.getName());//中华田园犬
console.log(333,cat.getName());//报错 cat.getName is not a function