I am curious as I get a "undefined is not a function" error. Consider the following class:
var FlareError = require('../flare_error.js');
class Currency {
constructor() {
this._currencyStore = [];
}
static store(currency) {
for (var key in currency) {
if (currency.hasOwnProperty(key) && currency[key] !== "") {
if (Object.keys(JSON.parse(currency[key])).length > 0) {
var currencyObject = JSON.parse(currency[key]);
this.currencyValidator(currencyObject);
currencyObject["current_amount"] = 0;
this._currencyStore.push(currencyObject);
}
}
}
}
currencyValidator(currencyJson) {
if (!currencyJson.hasOwnProperty('name')) {
FlareError.error('Currency must have a name attribute in the json.');
}
if (!currencyJson.hasOwnProperty('description')) {
FlareError.error('Currency must have a description attribute in the json.');
}
if (!currencyJson.hasOwnProperty('icon')) {
FlareError.error('Currency must have a icon attribute in the json.');
}
}
static getCurrencyStore() {
return this._currencyStore;
}
};
module.exports = Currency;
Refactoring aside, the issue is on the line: this.currencyValidator(currencyObject);
I get the error "undefined is not a function"
I assume this is because I have a static method who's internals call a non static method? Would that non static method have to be static? and if so does the concept of this.methodName
still work?