Created
November 16, 2016 03:54
-
-
Save dengjonathan/a7e932296571317f796842e4c7e4684b to your computer and use it in GitHub Desktop.
oop 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
//OOP | |
class Parent { | |
constructor(name, job) { | |
this.name = name; | |
this.job = job; | |
} | |
} | |
const solo = new Parent('Han', 'smuggler'); // {name: 'Han', job: 'smuggler'} | |
class Child extends Parent { | |
constructor(name, job, hero) { | |
this.name = name; | |
this.job = job; | |
this.hero = hero; | |
} | |
} | |
const ren = new Child('Kylo', 'Knight of Ren', 'Darth Vader') | |
// {name: 'Kylo', job: 'Knight of Ren', hero: 'Darth Vader'} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think you can call super() method to init name and job
Example:
class Child extends Parent {
constructor(name, job, hero) {
super(name, job);
this.hero = hero;
}
}
Documentation:
https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Classes/extends
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/super