Я пытаюсь сослаться на значение, возвращенное в предыдущем методе, в свойстве другого метода в другом свойстве
внутри конструктора, но я получаю сообщение "TypeError: Невозможно прочитать свойство 'name' of undefined"
class Loans {
constructor(user, loanAmount, tenor, id = 0, status = 'pending', repaid = 'false') {
this.id = id + 1;
this.user = user;
this.loanAmount = loanAmount;
this.tenor = tenor;
this.status = status;
this.repaid = repaid;
this.interest = (function interest() {
return (loanAmount * 0.05);
}());
this.monthlyInstall = (function monthlyInstall() {
return (loanAmount + this.interest) / tenor;
}());
this.balance = (function balance() {
return (loanAmount + interest);
}());
this.createdAt = new Date().toLocaleString();
};
};
const loan = new Loans('steve.jobs', 50000, 5);
console.log(loan);
but I got an error ->
return (loanAmount + this.interest) / tenor;
^
TypeError: Cannot read property 'interest' of undefined
at monthlyInstall (C:\Users\DEBAYO\Desktop\JavaScript\Challenges\testing.js:183:33)
at new Loans (C:\Users\DEBAYO\Desktop\JavaScript\Challenges\testing.js:184:6)