我的示例类:是在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