Last active
March 13, 2021 09:24
-
-
Save NovoManu/d95f4bcf68b326551c3294992c1b3b46 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Animal { | |
constructor(name) { | |
this.name = name | |
} | |
get getName() { | |
return this.name | |
} | |
set setName(newName) { | |
this.name = newName | |
} | |
} | |
class Dog extends Animal { | |
get bark() { | |
console.log(`${this.name} says woof woof`) | |
} | |
} | |
class Cat extends Animal { | |
get meow() { | |
console.log(`${this.name} says miaow`) | |
} | |
} | |
const dog = new Dog('Doggy') | |
const cat = new Cat('Kitty') | |
dog.bark // Expected output: Doggy says woof woof | |
cat.meow // Expected output: Kitty says miaow | |
dog.setName = 'Martin' | |
dog.bark // Expected output: Martin says woof woof |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment