---
title: "JSObjectMakeFunction(_:_:_:_:_:_:_:_:)"
framework: javascriptcore
role: symbol
role_heading: Function
path: "javascriptcore/jsobjectmakefunction(_:_:_:_:_:_:_:_:)"
---

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

Creates a function with a specified script as its body.

## Declaration

```swift
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 doc://com.apple.javascriptcore/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 doc://com.apple.javascriptcore/documentation/JavaScriptCore/JSStringRef array that contains the names of the function’s parameters. Pass NULL if parameterCount is 0.
- `body`: A doc://com.apple.javascriptcore/documentation/JavaScriptCore/JSStringRef that contains the script to use as the function’s body.
- `sourceURL`: A doc://com.apple.javascriptcore/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 doc://com.apple.javascriptcore/documentation/JavaScriptCore/JSValueRef to store an exception in, if any. Pass NULL to discard any exception.

## Return Value

Return Value A 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

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

## See Also

### Working with Objects

- [JSObjectCallAsConstructor(_:_:_:_:_:)](javascriptcore/jsobjectcallasconstructor(_:_:_:_:_:).md)
- [JSObjectCallAsFunction(_:_:_:_:_:_:)](javascriptcore/jsobjectcallasfunction(_:_:_:_:_:_:).md)
- [JSObjectCopyPropertyNames(_:_:)](javascriptcore/jsobjectcopypropertynames(_:_:).md)
- [JSObjectDeleteProperty(_:_:_:_:)](javascriptcore/jsobjectdeleteproperty(_:_:_:_:).md)
- [JSObjectGetPrivate(_:)](javascriptcore/jsobjectgetprivate(_:).md)
- [JSObjectGetProperty(_:_:_:_:)](javascriptcore/jsobjectgetproperty(_:_:_:_:).md)
- [JSObjectGetPropertyAtIndex(_:_:_:_:)](javascriptcore/jsobjectgetpropertyatindex(_:_:_:_:).md)
- [JSObjectGetPrototype(_:_:)](javascriptcore/jsobjectgetprototype(_:_:).md)
- [JSObjectHasProperty(_:_:_:)](javascriptcore/jsobjecthasproperty(_:_:_:).md)
- [JSObjectIsConstructor(_:_:)](javascriptcore/jsobjectisconstructor(_:_:).md)
- [JSObjectIsFunction(_:_:)](javascriptcore/jsobjectisfunction(_:_:).md)
- [JSObjectMake(_:_:_:)](javascriptcore/jsobjectmake(_:_:_:).md)
- [JSObjectMakeArray(_:_:_:_:)](javascriptcore/jsobjectmakearray(_:_:_:_:).md)
- [JSObjectMakeConstructor(_:_:_:)](javascriptcore/jsobjectmakeconstructor(_:_:_:).md)
- [JSObjectMakeDate(_:_:_:_:)](javascriptcore/jsobjectmakedate(_:_:_:_:).md)
