const A = function () {
function Animal() {
this.species = '动物';
this.friend = ['cow']
}
function Cat() {
this.eat = 'fish'
}
Cat.prototype = new Animal();
Cat.prototype.constructor = Cat;
let smallCat = new Cat();
let middleCat = new Cat();
console.log(smallCat.species, middleCat.species);
smallCat.species = '猫咪';
smallCat.friend.push('dog');
console.log(smallCat.friend, middleCat.friend);
}
const B = function () {
class Animal {
constructor() {
this.species = '动物';
this.friend = ['cow']
}
}
class Cat extends Animal {
constructor() {
super();
this.eat = 'fish'
}
}
let smallCat = new Cat();
let middleCat = new Cat();
smallCat.friend.push('dog');
console.log(smallCat.friend, 'smallCat.friend');
console.log(middleCat.friend, 'smallCat.friend')
}
B()
console