JS_GetFunctionObject 编辑
Retrieves the object for a specified function.
Syntax
JSObject *
JS_GetFunctionObject(JSFunction *fun);
Name | Type | Description |
---|---|---|
fun | JSFunction * | Pointer to a JS function. fun should be a native function or JSAPI-compiled function. See below. |
Description
JS_GetFunctionObject
returns the JavaScript Function
object for a specified function pointer, fun
.
fun
must be either a function implemented by a JSNative
(or JSFastNative
) or the result of a call to JS_CompileFunction
or similar functions. In other cases, the object returned by JS_GetFunctionObject
is not necessarily safe to call and should not be exposed to script.
In the JavaScript language, functions are objects. But in the JSAPI there are two separate concepts: a JSObject
is what is exposed to scripts and has properties and can be stored in variables; and the corresponding JSFunction
contains the code of a function. For certain functions, the two have a strictly one-to-one relationship, and for those functions it is safe to call JS_GetFunctionObject
to move from the JSFunction
to the JSObject
.
However, for other functions, and particularly for JavaScript closures, many JSObject
s may share the same JSFunction
. In these cases, this function should not be called. Calling the JSObject
returned by it could cause a crash or worse.
JS_GetFunctionObject
always returns a pointer to an object.
See Also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论