Lesesirkel JS:TGP kap 3
prototype eksperimentering
by andersand
HTML
<pre id="output">
</pre>
JavaScript
function A() {
this.a = "A from A";
this.b = "B from A";
}
function B() {
this.b = "B from B";
this.c = "C from B";
}
function C() {
this.b = "B from C";
this.c = "C from C";
}
var a = new A();
B.prototype = new A();
C.prototype = new A();
var b = new B();
var c = new C();
a.a = "tudeluu";
document.getElementById("output").innerHTML = "a.a " + a.a + "\n";
document.getElementById("output").innerHTML += "a.b " + a.b + "\n";
document.getElementById("output").innerHTML += "b.a " + b.a + "\n";
document.getElementById("output").innerHTML += "b.b " + b.b + "\n";
document.getElementById("output").innerHTML += "b.c " + b.c + "\n";
document.getElementById("output").innerHTML += "c.a " + c.a + "\n";
document.getElementById("output").innerHTML += "c.b " + c.b + "\n";
document.getElementById("output").innerHTML += "c.c " + c.c + "\n";