moinsen,
ein Auszug aus Object.create() was mich sehr stutzig macht.
// Shape - superclass
function Shape() {
this.x = 0;
this.y = 0;
}
// superclass method
Shape.prototype.move = function(x, y) {
this.x += x;
this.y += y;
console.info('Shape moved.');
};
// Rectangle - subclass
function Rectangle() {
Shape.call(this); // call super constructor.
}
// subclass extends superclass
Rectangle.prototype = Object.create(Shape.prototype);
Rectangle.prototype.constructor = Rectangle;.
//...
es geht mir um die Zuweisung Rectangle.prototype.constructor = Rectangle
. Was macht es für einen Unterschied ob die Konstruktor-Funktion Shape
oder Rectangle
enthält. Genau das macht meines Wissens nacht die letzte Zuweisung von Shape
nach Rectangle
zu wechseln.
Warum?
lgmb
--
Sprachstörung
Sprachstörung