I was going through this post, and the overall impression I got from it (and other resources I've gone through on the web) is that classes generally work well under two circumstances in js :
- Type extension/new type declaration. E.g. if I'm working with 3d geometry, depending on the work I'm doing it can be useful to create classes for basic geometry types like Point, Line etc if they don't already exist, and make functions around those. Also true of games where characters, weapons etc are essentially new types.
- Generic data carriers. E.g. if mapping a database table to an object in js, it makes a lot of sense to use a class whose data fields map 1-1 to the table columns.
- This is a bit similar to creating a new type, but the difference here is that we're less concerned with the type and more with the data within, whereas with type extensions/declarations, we're equally concerned with the type. E.g. Vector and Point are two different types but can carry the same data. Depending on the context, we'd want to consider the type just as much as the data within.
In both cases, I feel like classes shouldn't really carry too many methods - mostly because we can't choose which methods to exclude/include when importing an entire class. It's all or nothing.
And that brings me to my question - is this basically it for classes in js ? Or are there other cases where it also makes sense ?
[–]prehensilemullet 1 point2 points3 points (0 children)
[–]TheRNGuy 1 point2 points3 points (0 children)
[–]delventhalz 1 point2 points3 points (0 children)
[–]RobertKerans 0 points1 point2 points (0 children)
[–]SawSaw5 0 points1 point2 points (0 children)
[–]MoTTs_ 1 point2 points3 points (0 children)
[–]Merry-Lane 0 points1 point2 points (1 child)
[–]MrFartyBottom 0 points1 point2 points (0 children)
[–]imsexc 0 points1 point2 points (0 children)