function Account(id, balance, rate) {
this.id = id;
this.balance = balance;
this.rate = rate;
this.dateCreated = new Date();
this.getRate = function () {
return this.rate /= 12;
};
this.getMonthInterest = function () {
return this.balance * this.getRate();
};
this.withDraw = function (take) {
return this.balance -= take;
};
this.deposit = function (save) {
return this.balance += save;
};
}
let fun1 = new Account(1122, 20000, 0.045);
fun1.withDraw(2500) // 取款2500
fun1.deposit(3000) // 存款3000
console.log("余额:" + fun1.balance);
console.log("月利息:" + fun1.getMonthInterest()); // 打印月利息
console.log(fun1.dateCreated); // 打印开户日期