<!--
{
  "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/JSObjectMakeFunction(_:_:_:_:_:_:_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "JavaScriptCore"
    ],
    "preciseIdentifier" : "c:@F@JSObjectMakeFunction"
  },
  "title" : "JSObjectMakeFunction(_:_:_:_:_:_:_:_:)"
}
-->

# JSObjectMakeFunction(_:_:_:_:_:_:_:_:)

Creates a function with a specified script as its body.

```
func JSObjectMakeFunction(_ ctx: JSContextRef!, _ name: JSStringRef!, _ parameterCount: UInt32, _ parameterNames: UnsafePointer<JSStringRef?>!, _ body: JSStringRef!, _ sourceURL: JSStringRef!, _ startingLineNumber: Int32, _ exception: UnsafeMutablePointer<JSValueRef?>!) -> JSObjectRef!
```

## Parameters

`ctx`

The execution context to use.

`name`

A [`JSStringRef`](/documentation/JavaScriptCore/JSStringRef) that contains the function’s name. The system uses this when converting the function to a string. Pass `NULL` to create an anonymous function.

`parameterCount`

An integer count of the number of parameter names in `parameterNames`.

`parameterNames`

A [`JSStringRef`](/documentation/JavaScriptCore/JSStringRef) array that contains the names of the function’s parameters. Pass `NULL` if `parameterCount` is `0`.

`body`

A [`JSStringRef`](/documentation/JavaScriptCore/JSStringRef) that contains the script to use as the function’s body.

`sourceURL`

A [`JSStringRef`](/documentation/JavaScriptCore/JSStringRef) that contains a URL for the script’s source file. The system only uses this when reporting exceptions. Pass `NULL` if you don’t want to include source file information in exceptions.

`startingLineNumber`

An integer value that specifies the script’s starting line number in the file at `sourceURL`. The system only uses this when reporting exceptions.

`exception`

A pointer to a [`JSValueRef`](/documentation/JavaScriptCore/JSValueRef) to store an exception in, if any. Pass `NULL` to discard any exception.

## Return Value

A [`JSObjectRef`](/documentation/JavaScriptCore/JSObjectRef) that is a function, or `NULL` if either `body` or `parameterNames` contains a syntax error. The object’s prototype is the default function prototype.

## Discussion

Use this method when you want to execute a script repeatedly to avoid the cost of reparsing the script before each execution.

---

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)