一个demo说明class类与继承的用法
//父类
class Point {
//构造函数
constructor(x, y) {
this.x = x;
this.y = y;
return this
}
//原型
toString() {
return `(${this.x},${this.y})`
}
}
//子类
class Subpoint extends Point {
//子类构造函数
constructor(x, y, z) {
super(x, y);//先实例化父类属性
this.z = z;
return this
}
//子类原型
toString1() {
return `(${this.x},${this.y},${this.z})`
}
}
网友评论