It isn’t mentioned why a return statement is necessary in this instance, but not in the previous mixin and prototype chain challenges. If anyone could explain, ty!
When using a constructor or class (using the new keyword), Javascript follows a process:
Create a new empty object ({}).
Set the prototype of that object to the constructor.
Execute the constructor function, using that empty object as the context (this).
Unless the constructor stipulates an explicit return, the constructor returns that newly constructed object.
So with classes or constructors, we could manually do those steps ourselves. We could create our own object, wire it to a prototype chain, construct on that object, and explicitly return that.
But at that point, other than wiring it to the prototype chain, we’ve basically created a Factory Function or a Module.
Constructors and classes rely on inheritance, and the new keyword handles that for us. Modules and factories rely less on inheritance, as they create and compose the returned object themselves.