In chapter 6 (Code Reuse Patterns) there is following example:
// the parent constructor
function Parent(name) {
this.name = name || 'Adam';
}
// adding functionality to the prototype
Parent.prototype.say = function () {
return this.name;
};
// empty child constructor
function Child(name) {}
// inheritance magic happens here
inherit(Child, Parent);
In section "Classical Pattern #1 — The Default Pattern" the implementation of the inherit() function is:
function inherit(C, P) {
C.prototype = new P();
}
In the section "Drawbacks When Using Pattern #1" is the following example:
var s = new Child('Seth');
s.say(); // "Adam"
I don't understand the following author's explanation:
This is not what you’d expect. It’s possible for the child to pass parameters to the parent’s constructor, but then you have to do the inheritance every time you need a new child, which is inefficient, because you end up re-creating parent objects over and over.
How is it possible for the child to pass a parameter to the parent's constructor? And how is it possible to change the prototype of an child object after construction if not through the hidden prototype property? Could anyone please give me an example for that, what the author means?