What is the difference between defining functions using : and

I am woundering what the difference is between defining functions like this:

coolmodule = {}
function coolmodule.coolfunction()
    return("cooloutput")
end

And

coolmodule = {}
function coolmodule:coolfunction()
    return("cooloutput")
end

Is there any performance difference or is one way better then the other?

1 Like

: is used when the method passes self as its first parameter. In Luau, Roblox forces self as a first parameter. That is how self is recognized.

. is what you will use most commonly.

ex.

Object:func(arg, arg2) is the same as Object.func(Object, arg,arg2)

Dang, beat me to it. Good game.

So if I’m not using self would there be a performance difference between them?

No, they would be practically the exact same in every case if you don’t need self.

I suppose a minor performance implication may be there using : to pass self when its not needed but I don’t know enough to say if that’s something that should matter. I doubt it does.