In the Inheritance article for JavaScript Objects module, the instructions and example code advise to use the following snippet to update the Teacher.prototype.constructor
value from Person
to Teacher
after setting the prototype to Person
.
Object.defineProperty(Teacher.prototype, 'constructor', {
value: Teacher,
enumerable: false, // so that it does not appear in 'for in' loop
writable: true });
Later near the end of the Trying the example out section, the finished version code uses this snippet as expected.
However a short while later in the finished version of the A further exercise section, the Teacher.prototype.constructor value and that of the new Student class are set using a different method.
Teacher.prototype.constructor = Teacher;
...
Student.prototype.constructor = Student;
Both approaches appear to have the same result in the console however I can’t find the explanation for the second method. I can follow the logic easily enough but unsure if I missed a comparison of the two ways of setting the Class/Constructor.prototype.constructor property. Is there one I overlooked?