標籤: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 父子類 繼承關係