Contents

JSObjectCallAsFunctionCallback

The callback type for calling an object as a function.

Declaration

typealias JSObjectCallAsFunctionCallback = (JSContextRef?, JSObjectRef?, JSObjectRef?, Int, UnsafePointer<JSValueRef?>?, UnsafeMutablePointer<JSValueRef?>?) -> JSValueRef?

Parameters

  • ctx:

    The execution context to use.

  • function:

    A Jsobjectref that is the function to call.

  • thisObject:

    A Jsobjectref that is the this variable in the function’s scope.

  • argumentCount:

    An integer count of the number of arguments in arguments.

  • arguments:

    A JSValue array of the arguments to pass to the function.

  • exception:

    A pointer to a Jsvalueref to return an exception in, if any.

Return Value

A JSValueRef that is the function’s return value.

Discussion

If you name your function CallAsFunction, you declare it like this:

JSValueRef CallAsFunction(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);

If the JavaScript expression myObject.myFunction() invokes your callback, it sets function to myFunction, and thisObject to myObject.

If this callback is NULL, calling your object as a function throws an exception.

See Also

Managing Callbacks