types.Table.constructor
Method on every
tableconstructor(): any
Returns a new, empty table.
Return value
A fresh table with no keys, unrelated to the table constructor was called on.
Notes
Takes no arguments. Unlike a class's constructor, calling this one on an existing table t does not rebuild t in place: t.constructor() leaves t untouched and returns a different, empty table. Use clear to empty t itself, or the {} literal to make a new empty table directly; this method exists mainly so the table delegate has a constructor slot, matching every other type.
Example
let t = {a=1, b=2}
let r = t.constructor()
println("r.len() =", r.len()) // the result is a brand-new, empty table
println("t.len() =", t.len()) // t itself is untouched
println("r == t:", r == t)
// takes no arguments at all
try {
t.constructor(1)
} catch (e) {
println("t.constructor(1) throws:", e)
}Output:
r.len() = 0
t.len() = 2
r == t: false
t.constructor(1) throws: wrong number of parameters passed to native closure 'constructor' (2 passed, 1 required)See also
clone | Returns a shallow copy of the table. |
clear | Removes every key/value pair from the table, in place. |
| table | class index |