DEV Community

Discussion on: JavaScript Inheritance: The Dark Arts

Collapse
 
webduvet profile image
webduvet • Edited

What is wrong with example 4?
constructor of MyClass does not sit in MyClass.prototype. what a surprise that it does not get overriden...
I noticed that you are saying it is a bogus example. I just felt that unlike the other examples where it might look surprising to some the No.4 is just plain error.

Collapse
 
nickkelly314 profile image
Nick Kelly • Edited

The confusing part is this:

instance.constructor.prototype === Object.getPrototypeOf(instance); // false
Enter fullscreen mode Exit fullscreen mode

Which makes sense once you know that instance.constructor is accessing an altered constuctor property from the prototype, but otherwise might be quite confusing.

You're right that it probably doesn't belong with the other examples. Hopefully JavaScript developers unaware of prototype.constructor might find it interesting.