有什么区别吗
local splitPathFileExtension = function (res)
end
和
function splitPathFileExtension(res)
end
?我知道在第一种情况下这个函数是匿名的,但这是唯一的区别?
最佳答案
它们几乎完全相同(除了您将第一个函数指定为 local
而不是第二个函数。)
参见 manual关于函数定义:
The statement
function f () body end
corresponds to
f = function () body end
The statement
function t.a.b.c.f () body end
translates to
t.a.b.c.f = function () body end
The statement
local function f () body end
translates to
local f; f = function () body end
not to
local f = function () body end
(This only makes a difference when the body of the function contains references to f.)
关于lua - Lua 中的函数定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31604850/