5

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?

loganhuskins
  • 209
  • 2
  • 5
  • 1
    [When should I use static methods in a class and what are the benefits?](http://stackoverflow.com/a/11240227/102937) – Robert Harvey Sep 22 '16 at 22:53
  • 1
    [What is the gain from declaring a method as static?](http://stackoverflow.com/a/11240227/102937) – Robert Harvey Sep 22 '16 at 22:54
  • 2
    Possible duplicate of [Make methods that do not depend on instance fields, static?](http://programmers.stackexchange.com/questions/215826/make-methods-that-do-not-depend-on-instance-fields-static) – Robert Harvey Sep 22 '16 at 22:55

1 Answers1

1

Don't just make the method static. Make it a function.

gardenhead
  • 4,719
  • 2
  • 19
  • 24
  • 2
    Agreed! 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