I'm reading this book and there is a chapter about prototypes with this hard to understand paragraph and code snippet.
When you make a new object, you can select the object that should be its prototype. The mechanism that JavaScript provides to do this is messy and complex, but it can be significantly simplified. We will add a beget method to the Object function. The beget method creates a new object that uses an old object as its prototype.
if (typeof Object.beget !== 'function') {
Object.beget = function (o) {
var F = function () {};
F.prototype = o;
return new F();
};
}
var another_stooge = Object.beget(stooge);
Could you please explain this code, why is this good etc.? Which resource would you recommend to study prototypes? Here is it quite difficult.