功能使用Object.create和简单重新分配原型之间的任何区别?

时间:2018-06-12 17:59:39

标签: javascript object inheritance prototype

我想知道使用Object.create()和简单重新分配之间是否有任何区别?

使用Object.create()

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;

重新分配

{{1}}

0 个答案:

没有答案
相关问题