Polymorphic implementations are able to use and inherit similar methods. First, you define an abstract class. Some virtual methods are called. Virtual methods are not defined in abstract classes. Instead, it is implemented through its detailed implementation class.
Examples are as follows:
Object.extend=function (Destination,source) {in source) {Destination[property]=source[property];} return destination;} Defines an abstract base class base, no constructor function base () {};base.prototype={ initialize:function () { this.oninit ();//calls a virtual method }} function Subclassa () {//constructor}subclassa.prototype=object.extend ({propinsubclassa: "Propinsubclassa", OnInit: function () {alert (This.propinsubclassa);}},base.prototype); function Subclassb () {//constructor}subclassb.prototype= Object.extend ({propinsubclassb: "Propinsubclassb", Oninit:function () {alert (THIS.PROPINSUBCLASSB);}}, Base.prototype); var obja=new subclassa (); obja.initialize ();//Output "Propinsubclassa" var objb=new subclassb (); O Bjb.initialize ();//Output "PROPINSUBCLASSB"
First, an abstract base class base is defined, and the OnInit method is called in the Initialize method of the base class, but the implementation or declaration of the OnInit method is not used in the base class.
The Subclassa and SUBCLASSB classes inherit from the base class, and the OnInit method is implemented in different ways.
Multi-state implementation in JS