简体   繁体   English

在扩展类中从异步方法调用超类'异步方法

[英]Calling super class' async method from async method in extending class

I'm writing JavaScript (> ECMAScript 6) and I can't figure how to call a super class' async method in an extending class' method. 我正在编写JavaScript(> ECMAScript 6),我无法想象如何在扩展类'方法中调用超类'异步方法。 This is what I'm trying to do: 这就是我想要做的:

class SuperClass {
    constructor(){}

    async method() {
        return;
    }
}

class ExtendClass extends SuperClass {
    constructor() {
        super();
    }

    async method() {
        return super.method();
    }
}

The above won't compile, getting this as error: 以上将无法编译,将此作为错误:

SyntaxError: 'super' keyword unexpected here
    at Object.<anonymous> (Path/To/File.js:line:character)

Am I actually trying to do something that isn't possible? 我是否真的想做一些不可能的事情? Can't seem to Google anything useful.. 谷歌似乎没什么用的..

It does not help to await the call to the super class, it does not help to have different method names - the only thing that helps is making the extending class' method non-async. 它等待对超类的调用没有帮助,它有助于拥有不同的方法名称 - 唯一有帮助的是使扩展类的方法非异步。

This is due to the transpilation used in the testing framework, TestCafe (as stated by @Bergi). 这是由于测试框架TestCafe中使用的转换(如@Bergi所述)。 I will direct the question elsewhere. 我将把问题引导到其他地方。 Thanks for the comments. 感谢您的评论。

UPDATE UPDATE

This is currently a bug in the TestCafe framework ( link to bug ). 这是TestCafe框架中的一个错误( 链接到bug )。 The workaround is as follows: 解决方法如下:

async method () {
    return await SuperClass.prototype.method.call(this)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM