O'Reilly logo
  • Karl Giesing thinks this is interesting:

A class is instantiated into object form by a copy operation:

From

Cover of You Don't Know JS: this & Object Prototypes

Note

This diagram is where we start to see the author get into trouble.

For example, b1 is not a "copy" of Bar, it is an instance of Bar. It holds a hidden reference to Bar, used when calling methods on b1. When you call b1.myMethod(), you don't call a copy of myMethod(). The compiler/interpreter follows the reference to Bar, finds a reference to the method implementation (in the class's vtable or similar), and invokes the code using that method reference.

If Foo implements myMethod, but Bar does not, Bar's vtable might not reference myMethod. In this case Foo's vtable is consulted. (Depends upon implementation.)

In other words, it might work exactly like it does in JS, exce...