我正在使用 redux 和 react。这使得 dispatch 作为组件中的 props 可用。因此,当我console.log(this.props)
在 dispatch 键下的日志中看到以下对象时。
[[Scopes]]: Scopes[5]
0:Closure
1:Closure
2:Closure (createThunkMiddleware)
3:Closure
4:Global
有人能解释一下这是什么吗?
我正在使用 redux 和 react。这使得 dispatch 作为组件中的 props 可用。因此,当我console.log(this.props)
在 dispatch 键下的日志中看到以下对象时。
[[Scopes]]: Scopes[5]
0:Closure
1:Closure
2:Closure (createThunkMiddleware)
3:Closure
4:Global
有人能解释一下这是什么吗?
[[Scopes]]
是 Chrome 开发人员工具在内部添加和使用的私有属性,在 C++ 中,在源代码中。它显示函数范围内的变量,即可以从该函数访问哪些变量。
例如:
function a() {
var foo = 'foo';
var obj = {
bar: function () {
return foo;
}
};
console.log(obj);
}
a();
在这里,附加到 property 的函数在其范围内obj.bar
有变量foo
,所以当我们检查[[Scopes]]
属性时,obj.bar
我们会看到类似
[[Scopes]]: Scopes[2]
0: Closure (a)
foo: "foo"
1: Global
(all global variables)
您可以在控制台中手动检查这些属性,这可能对调试有所帮助,但您无法使用 JavaScript 访问它们,也不应该在应用程序代码中关心它们。
另请参阅:SO - 以编程方式访问函数位置。