Skip to content

Instantly share code, notes, and snippets.

@quangkeu95
Last active November 7, 2018 08:09
Show Gist options
  • Save quangkeu95/de58d55b5a84e62879f9ab1a28a09f6d to your computer and use it in GitHub Desktop.
Save quangkeu95/de58d55b5a84e62879f9ab1a28a09f6d to your computer and use it in GitHub Desktop.
ES6 Class Inheritance
class Animal {
constructor(name, weight) {
this.name = name;
this.weight = weight;
}
eat() {
return `${this.name} is eating`;
}
sleep() {
return `${this.name} is going to sleep`;
}
}
class Dog extends Animal{
constructor(name, weight, sex) {
super(name, weight);
this.sex = sex;
}
run() {
return `${this.name} is running`;
}
eatBone() {
return `${super.eat()} bone`;
}
}
const dog = new Dog("Kem", "2kg");
console.log(dog.sleep());
console.log(dog.run());
console.log(dog.eatBone());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment