JS_GetScopeChain 编辑

Obsolete since JavaScript 1.8.7
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.

Retrieves the scope chain for the JavaScript code currently running in a given context.

JS_GetScopeChain has been removed in SpiderMonkey 1.8.7 with no identical replacement. When you only used this function to retrieve the scope chain's global, then you can use the function JS_GetGlobalForScopeChain.

Syntax

JSObject *
JS_GetScopeChain(JSContext *cx);
NameTypeDescription
cxJSContext *The context to query.

Description

JS_GetScopeChain returns the first JSObject on the scope chain for the JavaScript code currently running in the given context, cx.

The ECMAScript standard, ECMA 262-3 §10, describes execution contexts and scope chains. A scope chain is a sequence of objects whose properties are searched whenever a script or function refers to a variable. These objects represent the lexical scope of the currently executing statement or expression, not the call stack, so they include:

  • the variable objects of any enclosing functions or let statements or expressions, and any objects selected by enclosing with statements, in order from the most-nested scope outward;
  • lastly the global object against which the function was created.

Note that cx's current global object, as set by JS_SetGlobalObject, is not guaranteed to be on the scope chain. If the currently executing function was created in the scope of a different global object, then that object will be the last object in the current scope chain. If the context is currently executing a script, and not in any function, it's running in a scope that was passed to JS_ExecuteScript or a similar function by the application. This scope chain may or may not contain cx's current global object.

If any code is currently executing in cx, JS_GetScopeChain returns a pointer to the first JSObject on the current scope chain. Otherwise, if cx has a global object, JS_GetScopeChain returns that. Otherwise, an error is reported and JS_GetScopeChain returns NULL.

To walk the scope chain, use JS_GetParent.

See Also

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

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

发布评论

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

词条统计

浏览:55 次

字数:4635

最后编辑:7年前

编辑次数:0 次

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