26 ms·
Uhh yes, classes in JS is just function, but it forces you to make a strict definition on how the set of functions will behave, in opposite of defining function
by fendy3002 3y ago
Uhh yes, classes in JS is just function, but it forces you to make a strict definition on how the set of functions will behave, in opposite of defining functions and tied them up individually.
If a thing need properties and methods to operate, defining it as class won't make it harder to maintain than cleverly do it with functions and object.
- devjab 3y ago> but it forces you to make a strict definition on how the set of functions will behave This would be true if JavaScript had static dispatch, but since it doesn't, everything you do with your class is mutable all the way up the prototype object chain. One of the reasons this is harder to maintain, is because the "strictness" you think you build into your code isn't actually there unless everyone who works on your code after you follows the same rules you did. I'm sure we'd like to live in that world, but I doubt we will.
- tracker1 3y agoIt's slightly more now with private members, but still prototype based inheritance and definitely not the same. Composition will still usually perform better all said. If you want something more, better to use TypeScript or step to something like Rust+Wasm.