function newAccount( initlizedBanlance)
local self = { balance = initlizedBanlance}
local show = function( v )
self.balance = self.balance - v
end
local getBanlance = function()
return self.balance
end
return {
show = show,
getBanlance = getBanlance
}
end
acc = newAccount(200)
print(acc.getBanlance())
acc.show(100)
print(acc.getBanlance())
function newObject( value )
return function(action ,v)
if action == "get" then return value
elseif action =="set" then value = v
else
error("invalid action")
end
end
end
d = newObject( 0 )
print(d("get"))
d("set",10)
print(d("get"))