Skip to content
Functions & closuresReference

clonefunction

Represents copying of a function or closure.

Details#

Creates a separate callable copy of the supplied closure. Cloning is not a deep copy of captured tables or the environment: referenced values may remain shared. Use a clone to keep a callable value independently of the original function value.

Signature#

Luau
clonefunction(target: function): function

Parameters#

ParameterTypeDescription
targetfunctionThe exact function value to inspect or modify.

Returns#

A callable clone; target must be a function.

Examples#

Example

Luau
local state = { value = 7 }
local function read() return state.value end
local copy = clonefunction(read)
print(copy()) -- 7
state.value = 9
print(copy()) -- 9