JSFunction 编辑

JSFunction is a type in the JSAPI. The APIs JS_NewFunction, JS_DefineFunction, JS_CompileFunction, and their Unicode equivalents return values of type JSFunction *.

For native functions and JSAPI-compiled functions - that is, functions returned by the APIs listed above-there is a simple one-to-one relationship between the JSFunction and the corresponding JavaScript Function object. To get a JSFunction * given the JSObject * of a Function object, use JS_ValueToFunction. To get the JSObject * given the JSFunction *, use JS_GetFunctionObject.

For other function objects - that is, functions created by running JavaScript code containing function declarations or function-expressions-the relationship between the JSFunction * and the JSObject * is not well-defined. Different closures (Function objects) generated from the same source code may share the same JSFunction. As a result, some APIs (such as JS_CallFunction) that operate on JSFunctions do not work properly with closures. The documentation for each affected API contains a warning about the problem.

If the application can't be sure that a given function JSObject is either native or JSAPI-compiled, it must not use the affected APIs. Instead of using JS_CallFunction, for example, it must call JS_CallFunctionValue.

Function objects created by calling JS_NewFunction have two reserved slots for the application's use. See JS_NewFunction for details.

See Also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

词条统计

浏览:134 次

字数:3717

最后编辑:8年前

编辑次数:0 次

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