Difference between | . --dot and : --colon |

I am so confused right now because both works

function Data.De()
	print("De")
end

function Data:Do()
	print("Do")
end

what should i use, dots or colons when making a function?
thanks in advance

I think there’s no difference EXCEPT you can only use self with : functions only.

There isn’t really a difference as @calvin_coco stated,

This isn’t exactly the case, it depends on what type of punctuation you use

for Example, a ModuleScript

local module = {}

function module:Do(Hi: CFrame)

end

function module.Did(Hi: CFrame)

end
return module

Depending if you use a Colon or Period, it will determine what is self

  • If you use ., Using a Colon function will have self

  • If you use :, The Period functions wont appear and self is gone from the function

2 Likes

There is some misconception here. The module.Foo() actually implicitly sets its first parameter as self in the sugar syntaxing. Don’t expect to use module:Foo(CFrame) to work as intended. Actual syntax for that would then be module:Foo(module, CFrame). You can still use module.Foo() and there won’t be any implicit self.

function module.Foo(self, params)
    -- only when module:Foo(params) is called, will self manifest
    -- module.Foo(module, params) would be its equivalent
    print(self) 
end

function module:Foo(params)
    -- self is implicit
    print(self)
end
4 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.