代码控件无法进入 javascript 中的子类构造函数



我一直在学习如何自动化桌面应用程序,我正在使用Javascript at语言编写测试。因此,我的代码中有以下三个类:Actions、Button和AppElements。AppElement类创建Button元素的实例,该实例继承Actions类。从"names.js"导入*作为名称;

class Actions{

constructor(appObject){
this.object=(appObject); 
}

doubleclick(){
doubleClick(waitForObjectExists(this.object));
}

}
class Button extends Actions{
constructor(anElement){
this.object=anElement;
super(anElement);
}
}
class AppElements {       
get dashboardButton() { return new Button(names.contentButtonDashboardWcPushButton);}
}
export
{
Actions,
AppElements,
Button
};
import * as names from 'names.js';
function main() {
// attach the desktop application
let dash= new test.AppElements();
dash.dashboardButton.doubleclick();
}

但是,当从测试脚本(从主函数(调用属性dashboardButton((时,它首先转到行构造函数(appObject({但没有进入构造函数块,并给出以下错误

error Detail试图访问未初始化的此值。忘记在派生类中调用super((了吗?

正因为如此,Actions类永远无法调用,我也无法访问Actions类的任何方法。

如果我能得到一些帮助来解决的问题,那会很棒吗

这里说。。。

在构造函数中使用时,super关键字单独出现,并且必须在使用this关键字之前使用。super关键字还可以用于调用父对象上的函数。

所以试试:

class Button extends Actions {
constructor(anElement) {
super(anElement);
this.object = anElement;
}
}

相关信息:

  • Squish 6.6中的JavaScript扩展
  • 超级

最新更新