How to inherit static methods from base class in JavaScript?

后端 未结 6 1581
长情又很酷
长情又很酷 2020-12-24 07:53

I\'m trying to achieve some basic OOP in JavaScript with the prototype way of inheritance. However, I find no way to inherit static members (methods) from the base class.

6条回答
  •  暖寄归人
    2020-12-24 08:17

    In the classical (OO) inheritance pattern, the static methods do not actually get inherited down. Therefore if you have a static method, why not just call: SuperClass.static_method() whenever you need it, no need for JavaScript to keep extra references or copies of the same method.

    You can also read this JavaScript Override Patterns to get a better understanding of how to implement inheritance in JavaScript.

提交回复
热议问题