lua面向对象铺垫

Account =
{
  balance = 0,
  withdraw = function(self, v)
    self.balance = self.balance - v
  end
}
--:操作符隐藏了self或者this参数,操作方便
function Account:deposit(v)
  self.balance = self.balance + v
end
--用.操作就需要指定操作的类型
Account.deposit(Account, 200.00)
Account:withdraw(100.00)

 

posted @ 2015-03-10 00:39  zzyoucan  阅读(136)  评论(0编辑  收藏  举报