If I am not mistaken I think what it does is just sets a function to a variable. It possibly by theory would work but I would personally just stick to the normal way doing it.
So An anonymous function expression is a function without a name that is assigned to a variable. You access and call the function through the variable to which it is assigned.
On the other hand, a named function declaration is a function with a name that is directly defined in the current scope. You can call the function using its name.
Both ways of defining functions are valid, but the main difference is in how you access and call them. With an anonymous function expression, you access and call the function through the variable to which it is assigned. With a named function declaration, you directly call the function using its name…
defining a function like this gives the function access to the func variable, it’s also the prefered way to define a function as it is more readable.
local function func()
print("hey")
return func
end
func()()
local func2 = function()
print("hey")
return func2
end
-- will error because the function did not have access to the func2 variable
func2()()
you can still achieve this with the other method by doing it like this, but there’s no reason to do so.
local func2
func2 = function()
print("hey")
return func2
end
func2()()