4 ms·
Classes don't really exist in JS. They're (mostly) syntactic sugar for OOP programmers. e.g. https://stackoverflow.com/questions/36419713/are-es6-classes-just-s
by ordinaryperson 8y ago
Classes don't really exist in JS. They're (mostly) syntactic sugar for OOP programmers. e.g. https://stackoverflow.com/questions/36419713/are-es6-classes-just-syntactic-sugar-for-the-prototypal-pattern-in-javascript https://stackoverflow.com/questions/36419713/are-es6-classes...
- jchw 8y agoBy 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, ...)`.
- JeremyBanks 8y agoThe prototype concept is little more than an annoying implementation detail for vendors to worry about. No use of it other than the `class` pattern ever saw any adoption. It causes more confusion every day than it provided distinct value in the last decade. With any luck we'll have so completely abstracted over it by ES12 that it won't even need to be mentioned in the spec.
- vbezhenar 8y agoFor me they definitely exist in JS. Prototypes are just an implementation detail.