types.Function.clone
Method on every
functionclone(): any
Returns the closure itself: unlike a table, array or class instance, a closure has no separate clone identity.
Return value
The same closure clone was called on - clone f == f is always true.
Notes
clone is a keyword as well as a method name, so by default f.clone() and f.$clone() do not parse. Use the bracket form, f["clone"](), or the operator form, clone f. Both reach this same method. With #forbid-clone-operator the word is an ordinary identifier and f.$clone() compiles.
Cloning a closure to attach a different environment is a different operation, done with bindenv, which does return a new closure.
Example
function f() {}
let g = clone f
println("f == g =", f == g)
let h = f["clone"]()
println("f == h =", f == h)Output:
f == g = true
f == h = trueSee also
weakref | Returns a weak reference to the closure. |
bindenv | Returns a copy of the closure with env statically bound as its this: every future call to the copy uses env, no matter how it is called. |
| function | class index |