How do I create an abstract base class in JavaScript?

后端 未结 17 2166
無奈伤痛
無奈伤痛 2020-12-02 04:06

Is it possible to simulate abstract base class in JavaScript? What is the most elegant way to do it?

Say, I want to do something like: -

var cat = ne         


        
17条回答
  •  天涯浪人
    2020-12-02 05:08

    You can create abstract classes by using object prototypes, a simple example can be as follows :

    var SampleInterface = {
       addItem : function(item){}  
    }
    

    You can change above method or not, it is up to you when you implement it. For a detailed observation, you may want to visit here.

提交回复
热议问题