class Dog {
constructor(name, age, type) {
this.name = name;
this.age = age;
this.type = type;
}
async eat() {
console.log(`${this.name} is eating.`);
await new Promise(resolve => setTimeout(resolve, 2000));
console.log(`${this.name} has finished eating.`);
return this;
}
}
const dudu = new Dog("嘟嘟", 3, "泰迪");
dudu.eat().then((dog) => {
console.log(dog)
dog.eat()
})
class Cat {
constructor(name, age, type) {
this.name = name;
this.age = age;
this.type = type;
}
async eat() {
console.log(`${this.name} is eating.`);
await new Promise(resolve => setTimeout(resolve, 2000));
console.log(`${this.name} has finished eating.`);
}
}
const rourou = new Cat('肉肉', 8, '加菲')
rourou.eat().then(() => {
console.log(rourou)
rourou.eat()
})