大熊君,那个转账的这样写有问题??

<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>

  

转载于:https://www.cnblogs.com/taomeng/p/4243973.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值