Inheritance
Trying out the cool stuff in ES6 that I learned here https://developer.mozilla.org/en/docs/Web/JavaScript/Inheritance_and_the_prototype_chain and here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes
by kshep92
JavaScript
"use strict";
class Person {
constructor(fname, lname) {
this.firstName = fname;
this.lastName = lname;
}
fullName() { return this.firstName + ' ' + this.lastName; }
}
class Student extends Person {
constructor(fname, lastname, courses) {
super(fname, lastname);
this.courses = courses;
}
}
class Teacher extends Person {
constructor(fname, lname, classes) {
super(fname, lname);
this.classes = classes;
this.students = [];
}
addStudent(student) {
this.students.push(student);
}
}
var s = new Student('Kevin', 'Sheppard', ['ict', 'met', 'phys']);
var t = new Teacher('Kevin', 'Rose', ["CHEM110D", 'PHYS201D']);
t.addStudent(s);
console.debug(t.fullName(), t.students, t.classes);