/** * Classes Class (Concept of Class) * */{//Basic definition and Build instance class parent{//Declaration class//Declaration constructor Constructor (name= ' Mukewang ') {
This.name=name;
}} let V_parent=new parent (' V '); Console.log (' constructors and instances ', v_parent);
V} {//Inherit class parent{//Parent class constructor (Name= ' Mukewang ') {this.name=name; }}//subclass Integrated Parent class child extends parent{} console.log (' Inheritance ', new Children ());
} {//Inherit pass parameter (subclass overrides parent class Value) class parent{//Parent class constructor (Name= ' Mukewang ') {this.name=name;
}} class Child extends parent{constructor (name= ' child ') {/** * Note: 1.super () Be sure to place the first line of the constructor * 2.super () pass the parameter list that overrides the parent class * 3. Generally used to override the default property or function of the parent class */super (name);
Use Super () to modify the value of the parent class this.type= ' child '; }} console.log (' Inherit pass parameter ', new child (' Hello '));
Hello child} {//Class Getter,setter Class parent{constructor (name= ' Mukewang ') {this.name=name; } get LongName () {Get property return ' Mk ' +this.name} set LongName (value) {//set property this.name=value;
}} let V=new Parent (); Console.log (' getter ', v.longname);
Mkmukewang v.longname= ' Hello '; Console.log (' setter ', v.longname); Mkhello}/** * Static method, is called through the class, rather than through the class instance to call */{class parent{constructor (name= ' Mukewang ') {This.name=nam
E
} static tell () {//static method definition Console.log (' tell '); }} Parent.tell ();
Invocation of a static method (called by Class)} {//static property class parent{constructor (name= ' Mukewang ') {this.name=name;
} static Tell () {console.log (' tell '); }} parent.type= ' Test '; Define static properties Console.log (' Static properties ', Parent.type);
Call a static property (called by Class)}