lua 闭包
实例1
functionnewCounter()locali=0--方法里的i变量不会被销毁returnfunction()--anonymousfunctioni=i+1returniendendc1=newCounter()print(c1())-->1print(c1())-->2
实例2
functionmyPower(x)returnfunction(y)returny^xendendpower2=myPower(2)--power2不单单拥有了方法myPower,并且拥有了参数2power3=myPower(3)print(power2(4))--4的2次方print(power3(5))--5的3次方
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。