JS_GetFunctionObject 编辑

Retrieves the object for a specified function.

Syntax

JSObject *
JS_GetFunctionObject(JSFunction *fun);
NameTypeDescription
funJSFunction *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 JSObjects 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:86 次

字数:4967

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文