【问题标题】:What are the variables [[FunctionLocation]], [[Scopes]]: in the Browser Console什么是变量 [[FunctionLocation]]、[[Scopes]]:在浏览器控制台中
【发布时间】:2020-11-21 23:23:59
【问题描述】:

当使用 jQuery Ajax 时,在浏览器控制台中,我可以看到 xhr 对象有两个 props / 字段,用一些奇怪的符号表示[双方括号,在这种情况下不认为它意味着数组];

首先,它们到底是什么,其次,我可以从我的 JavaScript 代码中访问这些值吗?

[[FunctionLocation]]: jquery-3.3.1.min.js:2
[[Scopes]]: Scopes[4]
0: Closure (w.Callbacks) {e: {…}, t: undefined, n: "", r: undefined, i: Array(0), …}
1: Closure {e: Window, r: document, i: ƒ, o: ƒ, a: ƒ, …}
2: Script {loc: Location, baseRestURL: "http://localhost:60123/MyVirtualDir"}
3: Global {parent: Window, opener: null, top: Window, length: 0, frames: Window, …}

【问题讨论】:

    标签: ajax jqxhr jquery-ajax


    【解决方案1】:

    不,您无法在代码中访问它们。

    您在 Inspector 中看到的 [[FunctionLocation]] 属性已添加到调试器 C++ 代码的 V8Debugger::internalProperties() 中,该代码使用另一个 C++ 函数 V8Debugger::functionLocation() 来收集有关该函数的信息。 functionLocation() 然后使用许多 V8 特定的 C++ API,例如 v8::Function::GetScriptLineNumber() 和 GetScriptColumnNumber() 来找出确切的信息。 上述所有 API 仅适用于 C++ 代码,而非 JavaScript 代码。如果您尝试在 Node.js 之类的平台上完成此任务,那么您应该能够编写一个原生模块。如果没有,那你就不走运了。

    here 还有一个类似的问题回答了

    [[Scopes]] 是 Chrome 开发者工具在 C++ 中添加和使用的私有属性,here in the source。它显示函数范围内的变量,即可以从该函数访问哪些变量。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-31
      • 2013-01-25
      • 2016-11-19
      相关资源
      最近更新 更多