lua anonymous

function newCounter()
    local i = 0 
    return function()
        i = i + 1 
        return i
    end 
end

c1 = newCounter()
c2 = newCounter()

print(c1())
print(c1())
print(c1())
print(c1())
print(c1())
print(c1())
print("\n")

print(c2())
print(c2())
print(c2())
print(c2())

1
2
3
4
5
6


1
2
3
4

 

posted @ 2017-08-22 13:35  hao.ma  阅读(173)  评论(0编辑  收藏  举报