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 JSFunction
s 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论