012-Classes Class (Concept of Class)

Source: Internet
Author: User
Tags constructor
/** * Classes Class (Concept of Class) * */{//Basic definition and Build instance class parent{//Declaration class//Declaration constructor Constructor (name= ' Mukewang ') {
    }} 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
    } 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)}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.