JS_NewFunction 编辑
Create a new JavaScript function that is implemented in C/C++ as a JSNative
.
Syntax
// Added in SpiderMonkey 45
JSFunction *
JS_NewFunction(JSContext *cx, JSNative call, unsigned nargs, unsigned flags,
const char *name);
// Obsolete since JSAPI 44
JSFunction *
JS_NewFunctionById(JSContext *cx, JSNative call, unsigned nargs, unsigned flags,
JS::Handle<jsid> id);
// Obsolete since JSAPI 39
JSFunction *
JS_NewFunction(JSContext *cx, JSNative call, unsigned nargs, unsigned flags,
JS::Handle<JSObject*> parent, const char *name);
JSFunction *
JS_NewFunctionById(JSContext *cx, JSNative call, unsigned nargs, unsigned flags,
JS::Handle<JSObject*> parent, JS::Handle<jsid> id); // Added in SpiderMonkey 17
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 | unsigned | Number of arguments the function expects. |
flags | unsigned | Pass JSFUN_CONSTRUCTOR to make a native that can be called as a constructor, otherwise 0 . |
parent | JS::Handle<JSObject*> | Pointer to the parent object for this function. If this is NULL , a default parent object is used. Obsolete since JSAPI 39 |
name | const char * | Name to assign to the new function. If this is NULL , the new function has no name. |
id | JS::Handle<jsid> | A pointer to jsid of the name to assign to the new function. Added in SpiderMonkey 17 |
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. If flags
is JSFUN_CONSTRUCTOR
, a created function can be called as a constructor. 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
- MXR ID Search for
JS_NewFunctionById
JS_CallFunction
JS_CallFunctionName
JS_CallFunctionValue
JS_CompileFunction
JS_CompileUCFunction
JS_DefineFunction
JS_DefineFunctions
JS_GetFunctionName
JS_GetFunctionObject
- bug 607695 - added
JS_NewFunctionById
- bug 1140573 - removed
parent
parameter - bug 1054756 - removed
JS_NewFunctionById
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论