types.Function.weakref
Method on every
functionweakref(): any
Returns a weak reference to the closure.
Return value
A weakref value. Calling its ref() method gives the closure back for as long as something else still holds a strong reference to it; once the closure's refcount drops to zero, ref() returns null instead.
Notes
Takes no arguments. This is a weak reference to the closure value itself - unrelated to the weak reference bindenv keeps on the environment it binds inside a closure.
Example
local f = function() {}
let w = f.weakref()
println("typeof w, (w.ref() == f) =", typeof w, w.ref() == f)
f = null
println("w.ref() =", w.ref())Output:
typeof w, (w.ref() == f) = weakref true
w.ref() = nullSee also
weakref | Returns a weak reference to the table. |
clone | Returns the closure itself: unlike a table, array or class instance, a closure has no separate clone identity. |
| function | class index |