types.Class.instance
classCreates a new instance of the class without running its constructor.
class Turret { active = false constructor() { this.active = true } }
let blueprint = Turret.instance()
println("blueprint.active =", blueprint.active)blueprint.active = falseReturn value
A new instance whose fields hold the class's plain declared defaults - the same values ClassName() would give them before the constructor runs, since Quirrel never clones a field's default value per instance (see types.Class.newmember's Notes on default values, and the language reference on class instances).
Notes
Locks the class as a side effect, the same as calling ClassName(...) does: a class permanently stops accepting new plain fields the first time any instance of it exists, whichever way that instance was made.
Useful for a class whose constructor requires arguments a caller does not have yet, or for tooling that wants a template instance to inspect without running arbitrary constructor code.
Example
class Widget {
ready = false
constructor() { this.ready = true }
}
let viaCall = Widget()
let viaInstance = Widget.instance()
println("viaCall.ready =", viaCall.ready)
println("viaInstance.ready =", viaInstance.ready)viaCall.ready = true
viaInstance.ready = falseSee also
call | Creates a new instance of the class and runs its constructor, the same as writing ClassName(...). Exists so a class value obtained indirectly (through a variable, a table slot, or getclass()) can still be instantiated through a uniform .call(...) spelling shared with functions. |
getclass | Returns the class this instance was constructed from. |
lock | Locks the class immediately, without creating an instance. |
| class | class index |