How I learned from a crazy idea / Subclassing an 'old' class in an ES6 class
by Arnaud Buchholz
HTML
<script src="https://arnaudbuchholz.github.io/blog/jsfiddle-assert.js"></script>
JavaScript
function OldA () {
this._a = "A";
}
OldA.prototype.a = function () {
return this._a;
};
class ExtendOldWithEs6B extends OldA {
constructor () {
super();
this._b = "B";
}
b () {
return this._b;
}
}
var b = new ExtendOldWithEs6B();
assert(() => b instanceof OldA);
assert(() => b.a() === "A");
assert(() => b instanceof ExtendOldWithEs6B);
assert(() => b.b() === "B");