gpt4 book ai didi

lua - Lua 中的函数定义

转载 作者:行者123 更新时间:2023-12-04 23:14:05 25 4
gpt4 key购买 nike

有什么区别吗

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com