Exercise 7.3

This commit is contained in:
Karan 2021-11-24 21:04:35 +05:30 committed by GitHub
parent b5789a143e
commit 8a5e6d002c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

17
Chapter 7/Exercise 7.3 Normal file
View File

@ -0,0 +1,17 @@
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);