// Person类 function Person (name) { let age; this.name = name; this.setAge = function (num) { age = num; } this.getAge = function () { return age; } } // 继承Person的Teacher类 function Teacher () { let studentCount; this.setStudentCount = function (num) { studentCount = num; } this.getStudentCount = function () { return studentCount; } } Teacher.prototype = new Person (); Teacher.prototype.constructor = Teacher;