2 ms·
By this logic what differentiates JS classes versus, say, C++ classes? C++ classes compile down to almost nothing. Non-virtual calls are static dispatch, virtua
by jchw 8y ago
By this logic what differentiates JS classes versus, say, C++ classes? C++ classes compile down to almost nothing. Non-virtual calls are static dispatch, virtual calls are just an indirection into a vtable.
I suppose the main difference is that in JS the implementation semantics of classes are defined and can be prodded at. Is that really so different though? I think it's just a bit strong to say ES classes "don't exist" because the methods by which they operate can be observed at a lower level.
- zamalek 8y ago> virtual calls are just an indirection into a vtable. Exactly, and `.prototype` is just a runtime and programmable vtable. You copy (by reference) everything from the base prototype and replace (override) every member that you need to. You can even call overridden methods with `BaseType.prototype.foo.call(this, ...)`.