Quais são as diferenças entre Rectangle.prototype = Object.create (Shape.prototype) e Rectangle.prototype = Shape.prototype?
Eu estava lendo os seguintes códigos e comecei a me perguntar Quais são as diferenças entreRectangle.prototype = Object.create(Shape.prototype)
eRectangle.prototype = Shape.prototype
? desde que Object.create (Shape.prototype) e Shape.prototype retornam um Object.
//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);