JS__class 入坑 chrome測試class 父子類 繼承關係

來源:互聯網
上載者:User

標籤:span   struct   return   over   不能   his   調用   ons   測試   

emmm...直接通過測試來看父子關係吧:

class A{    constructor(){//並非必須        this.name="class_A";        //console.log(this) //A {name: "class_A"} (另起一行)B {name: "class_A"} //父類子類分別執行了一次    }    static staticCallNameA(){    return "name_A";    }    callNameA(){    return "name_A";    }    static cover(){    return "cover_A"    }}class B extends A{    constructor(){//子類可以不加    super();//子類必須有    //console.log(this)//B {name: "class_A"} //會直接列印    }    static staticCallNameB(){    return "nameB";    }    callNameB(){    return "name_B";    }    static cover(){    return "cover_B"    }}
console.log(A.name,B.name) //A B //(類名)console.log(A.staticCallNameA(),B.staticCallNameA()) //static子類繼承父類console.log(A.cover(),B.cover()) //cover_A cover_B //先讀子類再讀父類console.log(A.staticCallNameB) //undefined //父類不具備子類特有函數console.log(A.callNameA,B.callNameA) //undefined undefined //非static方法類不能直接調用let a=new A(),b=new B; //加不加括弧效果一樣console.log(a.name); //class_Aconsole.log(a.name,b.name) //class_A class_Aconsole.log(a.callNameA(),a.callNameB,b.callNameB(),b.callNameA()) //name_A undefined name_B name_A //說明繼承關係同上

歡迎各位大神指點...

JS__class 入坑 chrome測試class 父子類 繼承關係

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.