Purpose of Static Methods in ECMAScript 6 Classes

后端 未结 2 1274
臣服心动
臣服心动 2020-12-18 00:05

What sort of issues with ES5 are static class methods in ES6 supposed to deal with?

The Babel documentation has the following example in its section regarding ES6 cl

2条回答
  •  隐瞒了意图╮
    2020-12-18 00:44

    Consider class that contains only static methods:

    class MyNamespace {
      static foo() { ... }
      static bar() { foo(); }
    }
    

    It is quite convenient way of organizing code - put stuff in namespaces.

    MyNamespace.foo();
    MyNamespace.bar();
    

    That's other than standard static method use cases in other OOP languages.

提交回复
热议问题