标签: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_A console.log(a.name,b.name) //class_A class_A console.log(a.callNameA(),a.callNameB,b.callNameB(),b.callNameA()) //name_A undefined name_B name_A //说明继承关系同上
欢迎各位大神指点...
JS__class 入坑 chrome测试class 父子类 继承关系
标签:span struct return over 不能 his 调用 ons 测试
原文地址:https://www.cnblogs.com/xin-note/p/9604463.html