Last active
November 7, 2018 08:09
-
-
Save quangkeu95/de58d55b5a84e62879f9ab1a28a09f6d to your computer and use it in GitHub Desktop.
ES6 Class Inheritance
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, 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