之间的区别。和:在Lua [英] Difference between . and : in Lua
本文介绍了之间的区别。和:在Lua的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我很困惑通过。
和通过函数调用之间的区别:
> x = {foo = function(a,b) return a end, bar = function(a,b) return b end, }
> return x.foo(3,4)
3
> return x.bar(3,4)
4
> return x:foo(3,4)
table: 0x10a120
> return x:bar(3,4)
3
什么是:在做什么?
推荐答案
冒号用于实现传递 self
作为第一个参数。因此 x:bar(3,4)
应该与 x.bar(x,3,4)
相同。 。
The colon is for implementing methods that pass self
as the first parameter. So x:bar(3,4)
should be the same as x.bar(x,3,4)
.
这篇关于之间的区别。和:在Lua的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文