class Point {
constructor(x, y) {
this.x = x;
this.y = y;
this.test1();
}
test1(){
}
static staticTest1(){
}
}
class ColorPoint extends Point {
constructor(x, y, color) {
super(x, y);
this.color = color; // 正确
this.test2();
}
test2(){
}
static staticTest2(){
}
}
var p1 = new Point(2, 3);
var p2 = new ColorPoint(2, 3, 'red');
//实例里面公有的东西 === 所对应的类里面共享的东西(原型对象)
p2.__proto__ === ColorPoint.prototype; //true
//实例里面公有的东西中,包含的上一级公有的东西 === 所对应的类里面共享的东西(原型对象)中,包含的上一级共享的东西(上一级的原型对象) === 所对应的类的父类里面共享的东西(父类的原型对象)
p2.__proto__.__proto__ === ColorPoint.prototype.__proto__ === Point.prototype; //true
//由上可得,以下等式;故,ColorPoint.prototype 可理解为Point的一个特殊实例
p2.__proto__.__proto__ === Point.prototype === p1.__proto__;
p1.__proto__ === ColorPoint.prototype.__proto__;
//以下等式应把ColorPoint、Point看做一个构造函数,而不是类
//ColorPoint构造函数里,必须执行的部分 === 父类的构造函数
ColorPoint.__proto__ === Point; //true
Point == Point.prototype.constructor; //true