Skip to content

Instantly share code, notes, and snippets.

@Knighton910
Created April 23, 2022 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Knighton910/614720f4d52937829e9e82a0d62ce323 to your computer and use it in GitHub Desktop.
Save Knighton910/614720f4d52937829e9e82a0d62ce323 to your computer and use it in GitHub Desktop.
React Classes refresh
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