JS_GetFunctionId 编辑
Get a function's name as a JSString
.
Syntax
JSString *
JS_GetFunctionId(JSFunction *fun);
JSString *
JS_GetFunctionDisplayId(JSFunction *fun); // Added in Spidermonkey 17
Name | Type | Description |
---|---|---|
fun | JSFunction * | A JavaScript function. |
Description
JS_GetFunctionId
returns the name of a function, fun
, as a JSString
, or NULL
if fun
is unnamed. The returned string lives as long as fun, so you don't need to root a saved reference to it if fun is well-connected or rooted, and provided you bound the use of the saved reference by fun's lifetime.
JS_GetFunctionDisplayId
returns the display name of a function, fun
. This is the defined name if one was given where the function was defined, or it could be an inferred name by the JS engine in the case that the function was defined to be anonymous. This can still return nullptr if a useful display name could not be inferred. The same restrictions on rooting as those in JS_GetFunctionId
apply.
Examples
The name returned by JS_GetFunctionDisplayId
is the same as returned by JS_GetFunctionId
if the function explicitly has a name listed in the source, or if not it is an intelligently guessed name for the function based on its context in the source. If no smart name could be guessed for the function, then NULL
is returned. The returned string is guaranteed to live as long as fun
, so the application often does not need to root the string.
function f() {} // f
var x = function() {}; // x
var a = { b: function() {} }; // a.b
a.c = function() {}; // a.c
a.d = (function() { // a.d< -- the '<' loosely means "contributor to"
return function() {}; // a.d
})();
var Foo = function() { // Foo
var bar = function() {}; // Foo/bar
};
setTimeout(function() {}, 100); // no name, JS_GetFunctionDisplayId returns NULL
See Also
- MXR ID Search for
JS_GetFunctionId
- MXR ID Search for
JS_GetFunctionDisplayId
- bug 433529 - added
JS_GetFunctionDisplayId
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论