Hallo,
function Knopf(x,y,beschriftung) {
//Super-Konstruktor aufrufen
EingabeElement.call(this,x,y);//Attribute
this.value = beschriftung;return this;
}
//Ableiten
Knopf.prototype = new EingabeElement();
Knopf.prototype.constructor = Knopf;
http://de.wikipedia.org/wiki/Javascript#Vererbung_.28prototype-Eigenschaft.29
Wozu braucht man call() denn überhaupt? In this.constructor steht eine Referenz zu EingabeElement. Denn Sinn von Knopf.prototype.constructor = Knopf verstehe ich nicht.
function EingabeElement(x,y) {
this.x = x;
this.y = y;
this.elementId = 0;
this.setX = function (sX) {
this.x = sX;
};
}
function Knopf (x, y, beschriftung) {
alert(this.constructor === EingabeElement);
this.constructor(x, y);
this.value = beschriftung;
}
Knopf.prototype = new EingabeElement();
var beispielknopf = new Knopf(1, 2, "Titel");
alert(beispielknopf.elementId);
beispielknopf.setX(3);
alert(beispielknopf.x + "\n" + beispielknopf.value);
Mathias