class Polygon {
constructor(height, width) {
this.name = 'Polygon';
this.height = height;
this.width = width;
}
sayName() {
console.log('Hi, I am a ', this.name + '.');
}
sayHistory() {
console.log('"Polygon" is derived from the Greek polus (many) ' +
'and gonia (angle).');
}
}
let p = new Polygon(300, 400);
console.log('p', p);
复制代码
class Child extends Polygon {
}
let c = new Child(1, 1);
console.log('c', c);
复制代码
class Child extends Polygon {
sayName() {
console.log('I am child')
}
}
let c = new Child(1, 1);
console.log('c', c);
复制代码
class Child extends Polygon {
constructor(height, width) {
super(height, width);
this.name = 'Child';
this.height = height;
this.width = width;
this.age = 18;
}
sayName() {
console.log('I am child')
}
}
let c = new Child(1, 1);
console.log('c', c);
复制代码