|
本帖最后由 rainviewer 于 2015-3-6 20:07 编辑
open.account=function(total){
list(
deposit=function(amount,total){
if(amount==0)
stop('Deposits must be positive!\n')
total=total+amount
cat(amount,"deposited. Your balance is",total,"\n\n")
},
withdraw=function(amount,total){
if(amount>total)
stop("You don't have that much money!\n")
total=total-amount
cat(amount,"withdraw. Your balance is",total,"\n\n")
},
balance=function(total){
total=total
cat("Your balance is",total,"\n\n")
total}
)
}
跪求分析:当运行这段代码时,total参数是怎么传递的?假设如下调用
total=100
ross=open.account(total)
ross$withdraw(30)
ross$balance()##怎么使得这条命令成功运行?
|
|