Extends
Extend before ES6
by XcsN
JavaScript
function A(conf, over) {
conf['a'] = over['a'] ? over['a'] : conf['a'];
this._a = conf['a'];
this._b = conf['b'];
this.onCreate = function (a, b, c) {
return c ? a[b] : b[a];
};
this.getA = function () {
return this._a;
};
this.getB = function () {
return this._b;
};
};
function B(conf, over) {
A.call(this, conf, over);
this.onCreate = function(a, b) {
return a + b;
};
}
B.prototype = Object.create(A.prototype);
var a = new A({a: 1, b: 2}, {a:3}),
b = new B({a: 4, b: 5}, {});
console.log(a.onCreate({b: '10'}, 'b', true));
console.log(a.getA());
console.log(a.getB());
console.log(b.onCreate(3, 5));
console.log(b.getA());
console.log(b.getB());