以ES5标准为例的继承方式
// 父类
function Base(a, b) {
this.x = a;
this.y = b;
this.arr = [a, b];
}
Base.prototype.add = function(a, b) {
this.x += a;
this.y += b;
}
// 子类
function Child(a, b, c) {
Base.call(this, a, b);
this.z = c;
}
Child.prototype.__proto__ = Base.prototype;
Child.prototype.print = function() {
console.log("print");
}
///
var base = new Base(1, 2);
base.add(1, 1);
var c1 = new Child(3, 4, 5);
c1.add(2, 2);
var c2 = new Child(6, 7, 8);
c2.add(3, 3);
c2.print();