What is this language feature called?

I was reading ROBLOX’s sword source code and noticed this code. I showed the function definition and it’s usage. I understand what it does, but what is this language feature called?

function Create(ty)
	return function(data)
		local obj = Instance.new(ty)
		for k, v in pairs(data) do
			if type(k) == 'number' then
				v.Parent = obj
			else
				obj[k] = v
			end
		end
		return obj
	end
end
Create("Animation"){
		Name = "R15Slash",
		AnimationId = BaseUrl .. Animations.R15Slash,
		Parent = Tool
	}

That would be a higher-order function (HOF). A higher-order function is a function that returns a function and/or accepts a function as an argument.

3 Likes

Hmm I think I see what the code is doing now considering you can call functions using function_name{}. So this code below would be identical?

function Create(ty, data)
		local obj = Instance.new(ty)
		for k, v in pairs(data) do
			if type(k) == 'number' then
				v.Parent = obj
			else
				obj[k] = v
			end
		end
		return obj
end
Create("Animation", {
		Name = "R15Slash",
		AnimationId = BaseUrl .. Animations.R15Slash,
		Parent = Tool
	})

Yes that would be identical, only that you don’t return a function anymore

1 Like

Ehh I’m not a fan of the original style, oh well that answers my question.

Neither am I. But they are useful for code reuse and to generalize them without having to rewrite them