Class example
by Arnaud Buchholz
JavaScript
function log (text) {
(document.body
.appendChild(document.createElement("div"))
.appendChild(document.createTextNode(text)));
}
function A () {
// A
}
function B () {
A.apply(this, []);
// B
}
B.prototype = new A();
B.prototype.superConstructor = A;
B.prototype.constructor = B;
var a = new A();
var b = new B();
log("a.constructor.name: " + a.constructor.name);
log("a instanceof A: " + (a instanceof A));
log("b.constructor.name: " + b.constructor.name);
log("b's base constructor.name: " + b.superConstructor.name);
log("b instanceof A: " + (b instanceof A));
log("b instanceof B: " + (b instanceof B));