<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.5.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "JavaScriptCore",
  "identifier" : "/documentation/JavaScriptCore/JSObjectCallAsFunctionCallback",
  "metadataVersion" : "0.1.0",
  "role" : "Type Alias",
  "symbol" : {
    "kind" : "Type Alias",
    "modules" : [
      "JavaScriptCore"
    ],
    "preciseIdentifier" : "c:@T@JSObjectCallAsFunctionCallback"
  },
  "title" : "JSObjectCallAsFunctionCallback"
}
-->

# JSObjectCallAsFunctionCallback

The callback type for calling an object as a function.

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

## Parameters

`ctx`

The execution context to use.

`function`

A [`JSObjectRef`](/documentation/JavaScriptCore/JSObjectRef) that is the function to call.

`thisObject`

A [`JSObjectRef`](/documentation/JavaScriptCore/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`](/documentation/JavaScriptCore/JSValueRef) to return an exception in, if any.

## Return Value

A [`JSValueRef`](/documentation/JavaScriptCore/JSValueRef) that is the function’s return value.

## Discussion

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

```c
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.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)