【发布时间】:2018-11-28 09:32:45
【问题描述】:
这样做的原因很复杂,但归结为不理解 mixins 或任何其他修改 ES6 类原型的方式。所以我回退到 ES5,但我不知道如何在没有new 的情况下调用 ES6 类的构造函数:
class A {
constructor() {}
}
function B() {
// what do I put here? I would do something like
// A.prototype.constructor.call(this) but that throws an error saying the
// constructor can only be called with `new`
}
B.prototype = Object.create(A.prototype);
【问题讨论】:
-
您是否有特定原因要避免使用
new?我认为调用new是唯一(并且是正确)的方法
标签: javascript ecmascript-6 ecmascript-5