1

I was wondering if there is any difference between using Object.create() and simply reassigning?

Using Object.create()

function Rectangle(length, width) {
  this.length = length;
  this.width = width;
}

function Square(size) {
  this.length = size;
  this.width = size;
}

Square.prototype = Object.create(Rectangle.prototype, {
  constructor: {
    configurable: true,
    enumerable: true,
    value: square,
    writable: true
  }
});

Reassigning

function Rectangle(length, width) {
  this.length = length;
  this.width = width;
}

function Square(size) {
  this.length = size;
  this.width = size;
}

Square.prototype = Rectangle.prototype;
Square.prototype.constructor = Square;
Jordan Running
  • 102,619
  • 17
  • 182
  • 182
akotch
  • 215
  • 5
  • 11

0 Answers0