I am using Typescript in Webstorm with Angular 2 and I am frequently getting warnings that a given method can be static. Yes, these specific methods do not depend on the state of the object they are a part of, but there will not be a time when it is used and the object is not instantiated. Should I still make those methods static?
Asked
Active
Viewed 4,052 times
5
-
1When should I use static methods in a class and what are the benefits? – Robert Harvey Sep 22 '16 at 22:53
-
1What is the gain from declaring a method as static? – Robert Harvey Sep 22 '16 at 22:54
-
2Possible duplicate of Make methods that do not depend on instance fields, static? – Robert Harvey Sep 22 '16 at 22:55
1 Answers
1
Don't just make the method static. Make it a function.

gardenhead
- 4,747
-
2Agreed! The only difference between a static method and a free function is the length of the name. If you really want a long name, then just give your function a long name. Putting it a class is pointless. – Daniel T. Sep 23 '16 at 03:02