0

The code contains

let a= new b();

It follows from this equality that a is an instance of type b, since it was created using new and the constructor function b. On the other hand, a .__ proto __ = b.prototype, that is, a prototypically inherits b.prototype. That is, we get that a inherits b and a inherits b.prototype (prototype). This is true? Does a inherit b?

  • `a` is an object and `b` is something like a `class`, so there is nothing to do with inheritance in this case – Ehsan Nazeri Oct 11 '20 at 17:16
  • "*`a` is an instance of an object of type `b`*" - no, `a` is simply an instance of "class" `b` (or type `b`, if you prefer). And by that statement we mean that `Object.getPrototypeOf(a) === b.prototype`. "*the object being created, of which `a` is an instance*" - there is no extra object involved, it's simply `a instanceof b`. If you mean the `b.prototype` object, that's not "being an instance of", that's just "inheriting from". – Bergi Oct 11 '20 at 17:58
  • Short answer: No, `a` does not inherit `b`, meaning `b` is not in `a`'s inheritance chain. Yes, `a` does inherit `b.prototype`, meaning `b` is at the head of `a`'s inhertance chain. For completeness, `a instanceof b` checks to see if `b.prototype` is anywhere along `a`'s inheritance chain. – traktor Oct 11 '20 at 23:56

0 Answers0