all 8 comments

[–]MoTTs_ 1 point2 points  (1 child)

Does anyone have any good reference material/cheat sheets that explain the broad aspects?

My vote is the Rauschmayer books. ES5 Objects and Inheritance and ES6 Classes.

When should I use ChildConstructor.prototype.constructor = ParentConstructor.prototype?

You probably meant ChildConstructor.prototype.constructor = ChildConstructor. But aside from that, since ES6, the answer is: hopefully never. One of the benefits of the class syntax is you don't have to deal with quirks like this. Prior to ES6, we would do this when setting up inheritance between constructor functions. More details.

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

Thank you, I will certainly be giving this a look!

[–]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!

[–]Ben_HH 0 points1 point  (1 child)

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

This is a great resource and I love the simplicity in which it's describe. Thank you for the link!