class Father {
constructor(x, y) {
this.x = x;
this.y = y;
}
sum() {
return this.x + this.y;
}
}
class Son extends Father {
subtract() {
return this.x - this.y;
}
}
var a = new Son(1, 1);
console.log(a.sum());
console.log(a.subtract());
这是没有加的控制台输出正常
class Father {
constructor(x, y) {
this.x = x;
this.y = y;
}
sum() {
return this.x + this.y;
}
}
class Son extends Father {
constructor(x, y) {
super(x, y);
}
subtract() {
return this.x - this.y;
}
}
var a = new Son(1, 1);
console.log(a.sum());
console.log(a.subtract());
这是加过了之后,控制台输出依然正常
请问这两种有区别吗?