大熊君,那个转账的这样写有问题??
<script language="JavaScript"> function Account(balance,rank){ this.balance = balance; this.rank = rank; } Account.prototype = { getBalance: function(){ return this.balance; }, getRank: function(){ return this.rank; }, setBalance: function(balance){ return this.balance = balance; } }; function TransferTrasaction(fromAccount,toAccount){ this.fromAccount = fromAccount; this.toAccount = toAccount; }; TransferTrasaction.prototype = { transfer: function(balance){ this.fromAccount.setBalance(this.fromAccount.getBalance() - balance); this.toAccount.setBalance(this.toAccount.getBalance() + balance); }, getFromAccount: function(){ return this.fromAccount; }, getToAccount: function(){ return this.toAccount; } }; function TransManager(transferTransaction){ this.transferTransaction = transferTransaction; this.rankVendor = { "normal":{ get: function(){return 1000;} }, "vip":{ get: function(){return 5000;} } }; } TransManager.prototype = { transfer: function(balance){ var transBalance = this.rankVendor[this.transferTransaction.getFromAccount().getRank()]['get'](); if(balance > transBalance){ alert('您的转账金额超出了规定范围!'); } if(this.transferTransaction.getFromAccount().getBalance() < balance){ alert('余额不足!'); } this.transferTransaction.transfer(balance); } }; var transferTransaction = new TransferTrasaction(new Account(8000,"vip"), new Account(3000,"normal")); var tt = new TransManager(transferTransaction) //debugger; tt.transfer("600"); var yue = tt.transferTransaction.fromAccount.getBalance(); document.write(yue); </script>
http://www.cnblogs.com/taomeng/