javascript - es6 implement polymorphism with extend -


look code below. a extend b , let b call sub-class's function implement polymorphism. if want add parameter b,since super() must call before use this.param = param,so can not via way pass parame b's polymorphism(). how make b's polymorphism() use custom param pass via b's constructor? there way make b's constructor can add parameter use custom business?

class a{     constructor()     {         this.polymorphism();     }     polymorphism(){         console.log("a")     } } class b extends a{     constructor(param)     {         super();     }     polymorphism()     {         console.log("b")         /**use param          * business code**/     } } new b() 


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -