I was reading the following codes, and start to wonder What are the differences between Rectangle.prototype = Object.create(Shape.prototype)
and Rectangle.pro
Rectangle.prototype = Shape.prototype;
is pointing Rectangle's prototype to the same object as Shape's prototype, meaning both prototypes are now the same object. So if you edit Rectangle.prototype.method
it will also appear at Shape.prototype.method
.
Rectangle.prototype = Object.create(Shape.prototype);
is creating a new object that inherits Shape's prototype, and assigning to Rectangle's, meaning if you edit Rectangle's prototype from this point, it won't affect Shape's. But if you edit Shape's prototype, you will get the same properties in Rectangle by inheritance.
Have a play - https://jsfiddle.net/j8o10zfn/