3 ms·
Developers of large JavaScript codebases have come to realize that class-based OO is exactly what they need. Prototype OO sounds interesting in theory, but in p
by epoch1970 11y ago
Developers of large JavaScript codebases have come to realize that class-based OO is exactly what they need. Prototype OO sounds interesting in theory, but in practice it tends to not be what's needed. Projects that use it end up trying to poorly imitate class OO. This wouldn't necessarily be a problem, except it isn't done consistently. There are multiple approaches, some of them which don't mesh well with others. Class-based OO, on the other hand, tends to be much more consistent and well-defined. This consistency improves developer productivity, it keeps the code cleaner, and it allows for greater code reuse between projects. Prototype OO hasn't proven itself in practice, while class OO has again and again.
- jasim 11y agoWould love to hear more about this. I've come to favour TypeScript style annotation with passing around hashes into pure functions in ES6.
- Bahamut 11y agoNot just that - there are performance implications as well due to browsers being able to use a fixed allocation of memory with classes' properties instead of a dynamically resized amount for objects, which results in less efficient algorithms able to be applied internally for the browser for doing similar operations.
- gsnedders 11y agoIn principle, in many cases it's possible to allocate the right amount of space for an object's properties, under the assumption that most objects from a single constructor gain properties in the same order.
- Roboprog 11y ago"Those people will go to their graves, never knowing how miserable they are" :-) See 5:30 into video (on ES6): https://www.youtube.com/watch?v=PSGEjv3Tqo0 https://www.youtube.com/watch?v=PSGEjv3Tqo0 I have been doing a fair amount of JS work in an app using Angular this year. I don't use much inheritance of any kind, mostly FP techniques and "objects" (associative arrays) as aggregates. If you use "closure" variables instead of "this", it's pretty easy to graft functions from one aggregate to another for code reuse.