在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
-- create class Account = {balance = 0} -- construct function Account:new(o) o = o or {} setmetatable(o,self) self.__index = self return o end function Account:deposit(v) self.balance = self.balance + v end function Account:withdraw(v) if v > self.balance then error"insuficient funds" end self.balance = self.balance -v end -- use example a = Account:new() print(a.balance) --> 0 a:deposit(1000.00) a:withdraw(100.00) print(a.balance) --> 900
|
请发表评论