types.Class.acall
Creates a new instance of the class, passing it the constructor arguments packed into an array. Equivalent to call, only with the arguments collected into one array instead of listed one by one.
... from the prose below, not from the signature.Parameters
args | array | array of constructor arguments; args[0] must be present but its value is ignored |
Return value
The new instance.
Errors
Throws a parameter type error if args is not an array. Takes exactly one argument beyond the receiver, so calling it with zero or two throws wrong number of parameters passed to native closure 'acall' (N passed, 2 required). Whatever the constructor itself throws propagates uncaught, same as calling ClassName(...) directly.
Notes
function.acall(array_args) documents array_args[0] as the required this object. Class.acall shares that array shape for consistency with Function.acall, but a class ignores whatever sits at args[0]: constructing an instance always supplies the new instance itself as this, so args[0] is only a placeholder and args[1] is the constructor's first real argument. Use null there for clarity. call has the same leading placeholder argument; see its Notes for the non-array form.
Example
class Rect {
w = 0
h = 0
constructor(w, h) { this.w = w; this.h = h }
}
// args[0] is a required placeholder; the class supplies its own instance as "this"
let r = Rect.acall([null, 3, 4])
println("r.w =", r.w, "r.h =", r.h)r.w = 3 r.h = 4See 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. |
pacall | Same as acall, except a failure does not invoke the VM's registered error callback. |
instance | Creates a new instance of the class without running its constructor. |
acall | Calls the closure with the arguments taken from an array: args[0] becomes this, and the rest of args becomes the closure's own parameters. |
| class | class index |