我的示例類:是在JS ECMAScript 6中繼承的構造函數嗎?
class Something{
constructor(x, y){
this.x = x;
this.y = y;
}
//...
}
當我會讓繼承類是這樣的:
class Dog extends Something{
constructor(name){
this.name = name;
}
//...
}
威爾狗的構造這個樣子的?
constructor(x, y, name){
this.x = x;
this.y = y;
this.name = name;
}
如果沒有,是否可以使它像這樣工作^?
您需要創建它明確使用'super'犬的構造像'超(X,Y);' – Andrey
你試試這個代碼?它會拋出一個異常,因爲你遺漏了'super'。 – loganfsmyth