Skip to content

Instantly share code, notes, and snippets.

@NovoManu
Last active March 13, 2021 09:24
Show Gist options
  • Save NovoManu/d95f4bcf68b326551c3294992c1b3b46 to your computer and use it in GitHub Desktop.
Save NovoManu/d95f4bcf68b326551c3294992c1b3b46 to your computer and use it in GitHub Desktop.
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