I am calling the method doSth2
of my class in the method doSth
of this class.
Now i can't access the attributes of this class. Instead I get
"Cannot read property 'idList' of undefined".
The scope must be wrong, so how do I access the attributes?
class Reset {
constructor(nameList, idList) {
this.nameList = nameList;
this.idList = idList;
}
doSth() {
console.log('Test' + this.idList[1]);
return this.nameList.forEach(this.doSth2);
}
doSth2(element, index) {
console.log(this.idList[index]);
}
}
var list1 = ["Label1", "Label2", "Label3", "Label4", "Label5"];
var list2 = ["ID1", "ID2", "ID3", "ID4", "ID5"];
const handler = new Reset(list1, list2);
handler.doSth();