Is it a good practice to put functions inside of class objects?
I am currently making a class called
MainRESTHandler
and it's going to have many functions, so I wanted to categorise the many functions in various objects. For example
3 Replies
Hmm, probably isn't the best way as I'm using TypeScript and typings don't really work ideally there...I'll stick with the old way I guess
Here's the thing with classes: it automatically handles the prototype for you so all of your methods inside the class are shared among all the various instances of
MainRESTHandler
s. So if you have a lot of them then you'll want a class with the methods declared within so you're not duplicating code.I see