Babel错误:类构造函数Foo不能被调用而没有'new' [英] Babel error: Class constructor Foo cannot be invoked without 'new'
问题描述
我有 class BaseComponent
,其扩展为 class Logger
。
当我在浏览器中运行新的Logger()
,我收到这个错误
类构造函数BaseComponent不能在没有'new'的情况下被调用
这是:
var Logger = function(_BaseComponent){
_inherits(Logger,_BaseComponent);
函数Logger(){
_classCallCheck(this,Logger);
return _possibleConstructorReturn(this,Object.getPrototypeOf(Logger).call(this,n)); // throws here
}
由于ES6类的工作方式,您不能使用泛型类扩展本机类。如果您的平台支持本地课程,我的建议是,而不是使用预设的 es2015
,请使用 es2015-node5
假设你在Node 5上。这将导致Babel跳过类的编译,以便你的代码使用本地类,而本地类可以扩展其他本地类。
I am using babel to transpile.
I have class BaseComponent
which is extended by class Logger
.
When I run new Logger()
in the browser, I am getting this error
Class constructor BaseComponent cannot be invoked without 'new'
the code that throws this is:
var Logger = function (_BaseComponent) {
_inherits(Logger, _BaseComponent);
function Logger() {
_classCallCheck(this, Logger);
return _possibleConstructorReturn(this, Object.getPrototypeOf(Logger).call(this, "n")); //throws here
}
Due to the way ES6 classes work, you cannot extend a native class with a transpiled class. If your platform supports native classes, my recommendation would be, instead of using the preset es2015
, use es2015-node5
, assuming you're on Node 5. That will cause Babel to skip compiling of classes so that your code uses native classes, and native classes can extend other native classes.
这篇关于Babel错误:类构造函数Foo不能被调用而没有'new'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!