How to inherit static methods from base class in JavaScript?

后端 未结 6 1580
长情又很酷
长情又很酷 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:22

    After your example code you can do this:

    for (var i in Class) {
        SomeClass[i] = Class[i];
    }
    

    to copy static members from Class to SubClass.

    If you're using jQuery, have a look at the jQuery.Class plugin from JavaScriptMVC. Or you can extend John Resig's Simple JavaScript Inheritance for a more library-agnostic system.

提交回复
热议问题