-- closure in Lua
local closure = function()
local __private = 0
return function ()
__private = __private + 1
return __private
end
end
local call = closure()
print(call()) --1
print(call()) --2
-- closure in Lua
local closure = function()
local __private = 0
return function ()
__private = __private + 1
return __private
end
end
local call = closure()
print(call()) --1
print(call()) --2
本文标题:lua 闭包
本文链接:https://www.haomeiwen.com/subject/nngwdttx.html
网友评论