JSObjectMakeFunction(_:_:_:_:_:_:_:_:)
Creates a function with a specified script as its body.
Declaration
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 that contains the function’s name. The system uses this when converting the function to a string. Pass
NULLto create an anonymous function. - parameterCount:
An integer count of the number of parameter names in
parameterNames. - parameterNames:
A Jsstringref array that contains the names of the function’s parameters. Pass
NULLifparameterCountis0. - body:
A Jsstringref that contains the script to use as the function’s body.
- sourceURL:
A Jsstringref that contains a URL for the script’s source file. The system only uses this when reporting exceptions. Pass
NULLif 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 to store an exception in, if any. Pass
NULLto discard any exception.
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
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(_:_:_:_:_:)JSObjectCallAsFunction(_:_:_:_:_:_:)JSObjectCopyPropertyNames(_:_:)JSObjectDeleteProperty(_:_:_:_:)JSObjectGetPrivate(_:)JSObjectGetProperty(_:_:_:_:)JSObjectGetPropertyAtIndex(_:_:_:_:)JSObjectGetPrototype(_:_:)JSObjectHasProperty(_:_:_:)JSObjectIsConstructor(_:_:)JSObjectIsFunction(_:_:)JSObjectMake(_:_:_:)JSObjectMakeArray(_:_:_:_:)JSObjectMakeConstructor(_:_:_:)JSObjectMakeDate(_:_:_:_:)