Created
September 19, 2020 14:03
-
-
Save saipraveen-a/e77a9e06ed50c911d9f0655c87e5e59e to your computer and use it in GitHub Desktop.
JavaScript Understanding the Weird Parts - Classes in ES6
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
// classes are just syntatic sugar in Javascript. They are just objects underneath | |
class Person { | |
constructor(firstName, lastName) { | |
this.firstName = firstName; | |
this.lastName = lastName; | |
} | |
greet() { | |
return 'Hi' + firstName; | |
} | |
} | |
var john = new Person('John', 'Doe'); | |
// Person object will be set as the Prototype __proto__ for the objects created using InformalPerson | |
class InformalPerson extends Person { | |
constructor(firstName, lastName) { | |
super(firstName, lastName); | |
} | |
greet() { | |
return 'Yo' + firstName; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment