-
-
Save Knighton910/614720f4d52937829e9e82a0d62ce323 to your computer and use it in GitHub Desktop.
React Classes refresh
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 Human { | |
constructor() { | |
this.gender = 'female' | |
} | |
printGender() { | |
console.log(this.gender) | |
} | |
} | |
class Person extends Human { | |
// Constructors are executed, whenever the class is instantiated | |
constructor() { | |
super(); // super keyword executes the parent constructor if you are extending a class. | |
this.name = 'Robin' | |
} | |
printName() { | |
console.log(this.name); | |
} | |
} | |
// Person instance | |
const person = new Person() | |
person.printName(); // "Robin" | |
person.printGender() // "female" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment