![](/img/trans.png)
[英]ES6 classes: is it possible to access the constructor of a child class from the parent?
[英]ES6 access functions from child class
鑒於以下代碼,如何從Parent
類訪問bar()
?
class Parent{
constructor(){
}
foo(){
this.bar() // not defined
}
}
class Child extends Parent{
constructor(){
super();
}
bar(){
}
}
你做你確實做到了訪問,但為了能在實際界定this
你必須創建一個Child
實例而不是Parent
之一:
var c = new Child();
c.bar() // works
c.foo() // calls c.bar() as well
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.