Javascript ';超级';生成器中的关键字意外
当试图在生成器中使用super关键字时,我得到以下错误Javascript ';超级';生成器中的关键字意外,javascript,node.js,ecmascript-6,babeljs,Javascript,Node.js,Ecmascript 6,Babeljs,当试图在生成器中使用super关键字时,我得到以下错误 base_model.js:82 yield super.$beforeInsert(context); ^^^^^ SyntaxError: 'super' keyword unexpected here 以下是源代码(通过Babel传输) 这是原始的源代码 class BaseModel extends Model { async $beforeInsert(context) {
base_model.js:82
yield super.$beforeInsert(context);
^^^^^
SyntaxError: 'super' keyword unexpected here
以下是源代码(通过Babel传输)
这是原始的源代码
class BaseModel extends Model {
async $beforeInsert(context) {
await super.$beforeInsert(context);
if (this.timestamps) {
this.created_at = new Date();
}
}
}
我正在使用NodeV6.3.1您是否也可以添加实际的源代码,这一个看起来像是一个传输的源代码。@cswl添加了原始源代码。我猜
super
需要在方法的范围内调用。在本例中,它是在生成函数的范围内调用的。或者,换句话说:您不能“推迟”调用super
。不幸的是,如果您不使用Transpile类,Babel目前不支持在异步方法中使用super
进行编译。似乎您正在使用排除类透明的预设。此处存档的错误:
class BaseModel extends Model {
async $beforeInsert(context) {
await super.$beforeInsert(context);
if (this.timestamps) {
this.created_at = new Date();
}
}
}