为什么经常用new Parent()而不是Object.create(Parent.prototype)来初始化children的原型?

Why is new Parent() often used to initialize prototypes of children instead of Object.create(Parent.prototype)?

Mozilla documentation page 的中间它切换(没有足够清楚的解释)示例来自

WorkerBee.prototype = Object.create(Employee.prototype);

WorkerBee.prototype = new Employee;

第二种形式 new Employee 将使用应该仅存在于 WorkBee 实例中的属性来初始化 WorkBee 的原型。

为什么在这么多 JavaScript 继承示例中使用第二种形式? 为继承的属性和自己的属性赋予不同的状态不是不受欢迎的吗?

WorkBee 中员工的状态 属性 名称与 属性 项目不同,因为名称是在 WorkBee.prototype.name 中定义的,而项目是在 WorkBee 实例上定义的。

一般来说,为什么有人会想要使用非抽象 class X 的构造函数来初始化 JavaScript 中派生的 class Y 的原型?

在我看来,两个构造函数都应该只用于初始化 X 和 Y 的实例,如果 Y 是从 X 派生的,那么构造函数 X 应该初始化 Y 的实例,而不是 Y 的原型。 但是如果 X 是抽象的,这意味着我们不希望有 X 的实例,只有这样我们才能潜在地使用 X 构造函数作为放置派生 classes.

原型的初始化的地方

Why is second form being used in so many examples of JavaScript inheritance?

因为我们没有摆脱它,它还在继续传播。另请参阅 here 了解一些历史。

Isn't it undesired to give different status to inherited properties vs own properties?

是的,绝对。