我正在学习在Javascript中使用Classes并遇到了一个问题。我无法在forEach中的构造函数中访问变量集。这是我的代码的样子:
class Debugger {
constructor(){
this.appList = [];
this.getApps().then(this.processApps);
}
getApps(){
return new Promise((resolve, reject) => {
System.getAllApplications(function (applicationInfoList) {
resolve(applicationInfoList);
});
});
}
processApps(apps){
apps.forEach(function(app){
this.appList.push(new Application(app.uuid));
});
}
}
我得到的错误是:无法读取未定义的属性'appList',大概是因为我的forEach循环中的这个没有引用我的类。这是什么样的正确模式?