loading...

re: Inheritance in JavaScript VIEW POST

FULL DISCUSSION
 

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;
  }
}
 

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.

code of conduct - report abuse