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 functionJS_GetGlobalForScopeChain
.Syntax
JSObject * JS_GetScopeChain(JSContext *cx);
Name | Type | Description |
---|---|---|
cx | JSContext * | 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 enclosingwith
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论