i don't get why everyone is using Boy.prototype = new Human;
to simulate inheritance. Look, what we want is the function's of A right? we can do that without instantiating a new A (in fact instantiating a new A does give us undesirable results, in the sense that we are actually running the instantiating function which isn't what we want)
So isn't this a better solution?
for (var prop_name in Human.prototype) {
Object.defineProperty(
Boy.prototype,
prop_name,
Object.getOwnPropertyDescriptor(Human.prototype,prop_name)
);
}
Say we are that particular and want not only the enumerable properties in Human.prototype we could still achieve it by using Object.getOwnPropertyNames
and calling it on the prototype chain, which in turn is available to us through Object.getPrototypeOf
.
So what exactly is the benefit of doing Boy.prototype = new Human;
to simulate inheritance when we have better options available to us?