JSFiddle - React, Tailwind, and code Playground

by Sabrina Luo

JavaScript

function Person(age) {
  this.age = age;
}

function Student(age, school) {
  Person.call(this, age);
  this.school = school;
}

function GoodStudent(age, school, grade) {
  Student.call(this, age, school);
  this.grade = grade
}

function Teacher(age, school) {
  Person.call(this, age);
  this.school = school;
}

Person.prototype.say = function() {
  console.log("hihihi", this.age);
}

Student.prototype = new Person();
GoodStudent.prototype = new Student();
Teacher.prototype = Object.create(Person.prototype);

var student = new Student(18, "bupt");
var teacher = new Teacher(25, "bupt");
var goodStudent = new GoodStudent(18, 'bupt', 100)

console.log(student, teacher, goodStudent);
console.log(student instanceof Person)
console.log(goodStudent instanceof Person, goodStudent instanceof Student)