18 lines
403 B
Groff
18 lines
403 B
Groff
class Animal {
|
|
constructor(species, sounds) {
|
|
this.species = species;
|
|
this.sounds = sounds;
|
|
}
|
|
speak() {
|
|
console.log(this.species + " " + this.sounds);
|
|
}
|
|
}
|
|
Animal.prototype.eat = function () {
|
|
return this.species + " is eating";
|
|
}
|
|
let cat = new Animal("cat", "meow");
|
|
let dog = new Animal("dog", "bark");
|
|
cat.speak();
|
|
console.log(dog.eat());
|
|
console.log(dog);
|