JavaScript-1.5 Reference

JS_DefineFunction Function

Summary

Creates a function and assigns it as a property to a specified JS object.

Syntax

JSFunction * JS_DefineFunction(JSContext *cx, JSObject *obj,
    const char *name, JSNative call, uintN nargs, uintN flags);
NameTypeDescription
cxJSContext *Pointer to a JS context from which to derive runtime information.
objJSObject *Object for which to define a function as a property (method).
nameconst char *Name to assign to the function.
callJSNativeIndicates the built-in, native C call wrapped by this function.
nargsuintNNumber of arguments that are passed to the function when it is called.
flagsuintNFunction attributes.

Description

JS_DefineFunction defines a single function and assigns it as a property (method) to a specified object, obj.

name is the name to assign to the function in the object. call is a built-in, native C call that is wrapped by your function. nargs indicates the number of arguments the function expects to receive. JS uses this information to allocate storage 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.

If it successfully creates the property, JS_DefineFunction returns a pointer to the 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_DecompileFunction | JS_DecompileFunctionBody | JS_DefineConstDoubles | JS_DefineElement | JS_DefineFunctions | JS_DefineObject | JS_DefineProperties | JS_DefineProperty | JS_DefinePropertyWithTinyId | JS_GetFunctionObject | JS_NewFunction | JS_SetBranchCallback | JS_ValueToFunction ]

This page was generated by APIDOC