types.Function.call
functionCalls the closure, using env as its this and forwarding the rest of the arguments as its own parameters.
Parameters
... | any | the first argument becomes this inside the call; the rest are forwarded as the closure's own arguments repeats |
Return value
Whatever the call returns.
Errors
Whatever the call itself throws, propagated unchanged.
Notes
env is not optional: f.call() fails with the arity error of f itself (zero arguments reached it, including the missing this), not an error from call. Anything beyond env is optional only in the sense that f may default or ignore it - call forwards what it is given.
When f is a non-native, non-generator closure, call tail-calls into it: the frame for this call does not stay on the stack, so f.call(env, ...) in a function's own tail position recurses as cheaply as a direct call. pcall never does this. Calling a generator-producing function through call behaves like calling it directly: it returns a new suspended generator without running the body.
Example
function greet(prefix) { return $"{prefix} {this.name}" }
let bob = {name = "Bob"}
println("greet.call(bob, \"Hi\") =", greet.call(bob, "Hi"))
// calling a generator-producing function through call() just creates the
// generator, exactly like calling it directly
function geny(n) { yield n }
let g = geny.call({}, 3)
println("typeof g + \" \" + resume g =", typeof g, resume g)greet.call(bob, "Hi") = Hi Bob
typeof g + " " + resume g = generator 3See also
pcall | Calls the closure like call does, using env as its this and forwarding the rest of the arguments as its own parameters. |
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. |
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 |