Hey all,
In this line:
[CODE]
function inherit(C, P) {
var F = function () {};
F.prototype = P.prototype;
C.prototype = new F();
}
Someone said that:
[CODE]
The new inheriting function will actually separate the constructor of the parent from the child, because it’s not pointing to the same object anymore, but now it’s pointing to a prototype of a newly created function that has nothing to do with the parent. So, you actually create a local copy of the parent’s constructor, and then create a new instance of the copy, which returns all constructor methods an properties. By changing the constructor of the child now, it will not affect the parent.
My question is I don’t understand how the child has nothing to do with the parent anymore when indeed we ASSIGN A REFERENCE of P prototype to F prototype. So F prototype must be pointing to P’s prototype. When we instantiate F, the above quote says it contains a copy, but not a reference? apply() creates COPIES but object assignment creates REFERENCES so when assigning prototype, isn’t a refeence, not a copy, created from P to F? And if it’s a reference, then that link from C to F to P should still exist. But obviously it doesn’t in the language so I am clearly missing something.
Thanks for any clarification.