- 传统方法
function extend(subClass,superClass)
{
var f=function(){}
f.prototype=superClass.prototype;
subClass.prototype=new f();
subClass.prototype.constructor=subClass;
if(superClass.prototype.constructor==Object.prototype.constructor)
superClass.prototype.constructor==superClass;
}
function Point(x, y){
_x: x,
_y: y
}
Point.prototype.toString = function() {
return this._x + ' ' + this._y;
};
function ColorPoint(x, y, color){
Point.apply(this,[x, y]);
this._color = color;
}
extend(ColorPoint, Point);
ColorPoint.prototype.toString = function() {
return this._color + ' ' + Point.toString();
};
var point1 = new ColorPoint(1, 2, 'yellow');


- ES6 class类继承方法
class Point {
constructor(x, y) {
this._x = x;
this._y = y;
}
toString() {
return this._x + ' ' + this._y;
}
}
class ColorPoint extends Point {
constructor(x, y, color) {
super(x, y);
this._color = color;
}
toString() {
return this._color + ' ' + super.toString();
}
}
let point1 = new ColorPoint(1, 2, 3);

两个继承的原理是相同的!!!