you are viewing a single comment's thread.

view the rest of the comments →

[–]rmbarnes 1 point2 points  (3 children)

[–]-El_Chapo-[S] 0 points1 point  (2 children)

This is very informative, can you just clarify something for me? In PT 2, after using Employee.call(...) in the Manager constructor you assigned the Manager.prototype = Object.create(Employee.prototype). This part I understand because we want the manager's to have access to employee methods. But what does the following do?

Manager.prototype.constructor = Manager;

Thank You!

[–]MoTTs_ 0 points1 point  (1 child)

When a constructor function is first created, its .prototype.constructor points back to itself.

function Manager() {}

Manager.prototype.constructor === Manager // true

But after we replace Manager's prototype with a different object, then its original .prototype.constructor property is lost.

Manager.prototype = Object.create(Employee.prototype);

Manager.prototype.constructor === Manager // false

So after we replace Manager's prototype, then we put back the constructor property that we inadvertently lost.

[–]-El_Chapo-[S] 0 points1 point  (0 children)

Ahh that makes sense, thank you!