我正在使用babel进行转换.
我有类BaseComponent,它由类Logger扩展.
当我在浏览器中运行新的Logger()时,我收到此错误
没有’new’就不能调用类构造函数BaseComponent
抛出这个的代码是:
var Logger = function (_BaseComponent) {
_inherits(Logger,_BaseComponent);
function Logger() {
_classCallCheck(this,Logger);
return _possibleConstructorReturn(this,Object.getPrototypeOf(Logger).call(this,"n")); //throws here
}
解决方法
由于ES6类的工作方式,您无法使用已转换的类扩展本机类.如果您的平台支持本机类,我建议使用es2015-node5,而不是使用预设的es2015,假设您在节点5上.这将导致Babel跳过编译类,以便您的代码使用本机类,并且本机类可以扩展其他本机类.