Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/401.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ';超级';生成器中的关键字意外_Javascript_Node.js_Ecmascript 6_Babeljs - Fatal编程技术网

Javascript ';超级';生成器中的关键字意外

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) {

当试图在生成器中使用super关键字时,我得到以下错误

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();
        }
    }
}