Skip to content

Instantly share code, notes, and snippets.

@saipraveen-a
Created September 19, 2020 14:03
Show Gist options
  • Save saipraveen-a/e77a9e06ed50c911d9f0655c87e5e59e to your computer and use it in GitHub Desktop.
Save saipraveen-a/e77a9e06ed50c911d9f0655c87e5e59e to your computer and use it in GitHub Desktop.
JavaScript Understanding the Weird Parts - Classes in ES6
// 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