JS NewFunction

Create a new JavaScript function that is implemented in C/C++ as a JSNative.

Syntax

JSFunction * JS_NewFunction(JSContext *cx, JSNative call,
   uintN nargs, uintN flags, JSObject *parent,
   const char *name);
Name Type Description
cx JSContext * The context in which to create the new function. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext.
call JSNative Native C/C++ implementation of this function.
nargs uintN Number of arguments the function expects.
flags uintN Reserved. Always pass 0 for this argument.
parent JSObject * Pointer to the parent object for this function. If this is NULL, a default parent object is used.
name const char * Name to assign to the new function. If this is NULL, the new function has no name.

Description

JS_NewFunction creates a new JavaScript function implemented in C/C++. (To create a new function implemented in JavaScript, use JS_CompileFunction instead.)

call is a C/C++ function pointer that the new function wraps. nargs is the number of arguments the function expects. flags must be 0. parent may be used to specify the new function's parent; NULL is usually the right thing here. name is the name to assign to the function. If name is NULL, the new function has no name. (JS_GetFunctionId, passed the new function, will return NULL.)

On success, JS_NewFunction returns a pointer to the newly created function. Otherwise it reports an out-of-memory error and returns NULL.

See Also

MXR ID Search for JS_NewFunction

JS_CallFunction, JS_CallFunctionName, JS_CallFunctionValue, JS_CompileFunction, JS_CompileUCFunction, JS_DefineFunction, JS_DefineFunctions, JS_GetFunctionName, JS_GetFunctionObject

Document Tags and Contributors

Last updated by: Jorend,