I have a class marketData:
export class marketData {
id: number;
denomCount: number;
itemCount: number;
conversionRates: Array<number> = [];
conversionRateToLowest: Array<number> = [];
itemPrices: Array<Array<number>> = [];
}
I would like to define a member function for it, validate(), that checks that the values of the class are set properly. I wrote part of this method to check itemPrices:
this.itemPrices.forEach(function(this, prices){
if(prices.length != this.itemCount){
// handle error
});
However, the above gives me a ERROR TypeError: "this is undefined". I got the exact same error trying to check itemPrices in this manner:
this.itemPrices.forEach(function(prices){
if(prices.length != this.itemCount){
// handle error
});
i.e. without the this in the function parameters.
What is the correct way to access the itemCount member variable?