0

Where is the benefit of using a static method instead of a non-static method? Of course, the static method is class-based and not instance-based and its intended to work as a helper function.

But how exactly is a non-static method not able to achieve the same results?

And how do i call a static method inside a class by another non-static class method in Javascript?

Kind regards

5
  • "But how exactly is a non-static method not able to achieve the same results?" if your method relies on some instance data, then you cannot have instance data in static methods. Ergo, you cannot have the same result with a static and non-static method in this case. Commented May 27, 2020 at 11:30
  • This is very little to do with javascript. You can google "static vs non-static" and check the results from any OOP language. "how do i call a static method inside a class by another non-static class method in Javascript". It's always called with yourClass.staticMethod() Commented May 27, 2020 at 11:34
  • please answer the question not by commenting it. Nevertheless you are right, adiga. @VLAZ : But i can rearrange the non-static method in that way that it can do the same tasks as the static method, or? Commented May 27, 2020 at 11:37
  • 1
    @ArgentHo depends. If your method is foo(a, b) { return a + b} then it makes little sense to be non-static. However, that doesn't mean that every non-static method can be made static and vice versa. For example, if you have a factory method, how exactly would you make it non-static? If you need an instance to call the factory, and you need to call the factory to get the instance, you have a chicken and egg problem. Commented May 27, 2020 at 11:42
  • you can call an static method without instantiating the class. otherwise you need first to instantiate the class before you can access the methods inside of it Commented May 27, 2020 at 11:43

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.