我已经创建了所有类(BankAccount,SavingAccount,CurrentAccount) 我的银行类有问题,我不知道为什么银行类中的功能没有执行。
这是我的代码(我没有包括所有功能):
class Bank {
constructor(){
this.accounts = [];
}
addAccount(acc) {
this.accounts.push(acc)
}
displayAllVAccounts(){
this.accounts.forEach(acc => console.log(acc));
}
}
module.exports = Bank;
应用类:
let BankAccount = require('./model/BankAccount');
let SavingAccount = require('./model/SavingAccount');
let CurrentAccount = require('./model/CurrentAccount');
let Bank = require('./model/Bank');
let saveAcc1 = new SavingAccount( 123 , 500 , 1000);
Bank.addAccount(saveAcc1);
let currAcc1 = new CurrentAccount ( 234 , 4000 ,15 );
Bank.addAccount(currAcc1);
let currAcc2 = new CurrentAccount ( 345 , 35000 , 25);
Bank.addAccount(currAcc2);
let saveAcc2 = new SavingAccount( 456 , 60000 , 1000);
Bank.addAccount(saveAcc2);
答案 0 :(得分:-2)
抢劫以下代码;
let Bank = require('./model/Bank');
let saveAcc1 = new SavingAccount( 123 , 500 , 1000);
new Bank().addAccount(saveAcc1);