Каковы различия между Rectangle.prototype = Object.create (Shape.prototype) и Rectangle.prototype = Shape.prototype?
Я читал следующие коды и начинаю задумываться, в чем разница междуRectangle.prototype = Object.create(Shape.prototype)
а такжеRectangle.prototype = Shape.prototype
? поскольку Object.create (Shape.prototype) и Shape.prototype возвращают объект.
//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);