标签:lua
实例1
function newCounter() local i = 0 --方法里的i变量不会被销毁 return function() -- anonymous function i = i + 1 return i end end c1 = newCounter() print(c1()) --> 1 print(c1()) --> 2
实例2
function myPower(x) return function(y) return y^x end end power2 = myPower(2) --power2不单单拥有了方法myPower,并且拥有了参数2 power3 = myPower(3) print(power2(4)) --4的2次方 print(power3(5)) --5的3次方
本文出自 “陪你度过漫长岁月” 博客,请务必保留此出处http://4774721.blog.51cto.com/4764721/1792278
标签:lua
原文地址:http://4774721.blog.51cto.com/4764721/1792278