3 ms·
+ Member access private/protected + Static members (theoretically exist in JS, but much cleaner and 'compiler aware' in TS) + Interfaces When I write JS, I end
by edblarney 10y ago
+ Member access private/protected
+ Static members (theoretically exist in JS, but much cleaner and 'compiler aware' in TS)
+ Interfaces
When I write JS, I end up with closures within closures within closures.
When I write TS, I find myself sticking to much cleaner abstraction. I end up (having to) create classes, and usually it's for the better.
- woah 10y agoA class is a pretty bad abstraction to try to fit the world into. It might work for some things, but it usually results in a lot of ceremony, and a lot of concepts in your program that exist only to service the abstraction. It's useful in JS for some special cases, but being forced into it is just going to make your code verbose and complicated for no reason. I'll stick to Flow for now.
- DanRosenwasser 10y agoFor the record, you're not forced into it at all. I'll mention that in the TypeScript compiler, we use very few classes at all - it's mostly written in a function-oriented style. TypeScript tries not to impose any sort of restrictions on coding style.
- edblarney 10y ago"A class is a pretty bad abstraction to try to fit the world into" I totally disagree with this. They are basically one of the best forms, if not 'the best' form of abstraction we have, particularly when it comes closer to the level of 'real world' abstraction. Classes are the basis of 'typing' - which is to say, typing beyond primitive types. They provide us with the ability to 'define things' that are not simply strings, numbers or booleans. It's why JS has moved onto classes, and almost all popular languages use them. The only time I find they can be limiting, is when there is the necessity to deal with looser typing, i.e. quick litoral objects ... but even then, 9 times out of 10 when I want to 'get around classes' - I'm just being lazy.