DEV Community

loading...

Discussion on: Inheritance in JavaScript

Collapse
karataev profile image
Eugene Karataev

Thanks for the reminder how inheritance works in JS.
I'm glad that with ES2015 we have classes and defining inheritance between objects is now straightforward, no need to touch prototypes anymore.

class Person {
  constructor(fn, ln) {
    this.firstName = fn;
    this.lastName = ln;
  }

  getFullName() {
    return this.firstName + ' ' + this.lastName;
  }
}

class Teacher extends Person {
  constructor(fn, ln, sbj) {
    super(fn, ln);
    this.subject = sbj;
  }
}
Collapse
acroynon profile image
Adam Roynon Author

Thank you for the comment, I really appreciate it. I agree, the new class system in JavaScript is so useful. The prototype chain can get so complicated when manually trying to manipulate objects.