JavaScript-1.5 Reference

JS_NewFunction Function

Summary

Creates a new JS function that wraps a native C function.

Syntax

JSFunction * JS_NewFunction(JSContext *cx, JSNative call,
    uintN nargs, uintN flags, JSObject *parent,
    const char *name);
NameTypeDescription
cxJSContext *Pointer to a JS context from which to derive runtime information.
callJSNativeNative C function call wrapped by this function.
nargsuintNNumber of arguments that are passed to the underlying C function.
flagsuintNFunction attributes.
parentJSObject *Pointer to the parent object for this function.
nameconst char *Name to assign to the new function. If you do not assign a name to the function, it is assigned the name "anonymous".

Description

JS_NewFunction creates a new JS function based on the parameters you pass. call is a native C function call that this function wraps. If you are not wrapping a native function, use JS_DefineFunction, instead. nargs is the number of arguments passed to the underlying C function. JS uses this information to allocate space for each argument.

flags lists the attributes to apply to the function. Currently documented attributes, JSFUN_BOUND_METHOD and JSFUN_GLOBAL_PARENT, are deprecated and should no longer be used. They continue to be supported only for existing applications that already depend on them.

parent is the parent object for this function. If a function has no parent, you can set parent to NULL. name is the name to assign to the function. If you pass an empty value, JS sets the function's name to anonymous.

If JS_NewFunction is successful, it returns a pointer to the newly created function. Otherwise it returns NULL.

See Also

Groups [ Function ]
Documents [ LXR ID Search ]
Entries [ JSFUN_BOUND_METHOD | JSFUN_GLOBAL_PARENT | JS_CallFunction | JS_CallFunctionName | JS_CallFunctionValue | JS_CompileFunction | JS_CompileUCFunction | JS_DecompileFunction | JS_DecompileFunctionBody | JS_DefineFunction | JS_DefineFunctions | JS_GetFunctionName | JS_GetFunctionObject | JS_SetBranchCallback | JS_ValueToFunction ]

This page was generated by APIDOC