function C(amount){
this.balance=amount; this.deposit=deposit; this.withdraw=withdraw; this.toString=toString; } function deposit(amount){ this.balance+=amount; } function withdraw(amount){ if(amount<=this.balance){ this.balance-=amount; } if(amount>this.balance){ alert("余额不足"); } } function toString(amount){ return "余额:"+this.balance; } var account=new C(500); account.deposit(1000); console.log(account.toString());account.withdraw(750);
console.log(account.toString());account.withdraw(375);
console.log(account.toString());