Was sind die Unterschiede zwischen Rectangle.prototype = Object.create (Shape.prototype) und Rectangle.prototype = Shape.prototype?
Ich habe die folgenden Codes gelesen und mich gefragt, was die Unterschiede zwischen @ sinRectangle.prototype = Object.create(Shape.prototype)
undRectangle.prototype = Shape.prototype
? da sowohl Object.create (Shape.prototype) als auch Shape.prototype ein Objekt zurückgeben.
//Shape - superclass
function Shape() {
this.x = 0;
this.y = 0;
}
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.
}
Rectangle.prototype = Object.create(Shape.prototype);