redux的dispatch()中的[[Scopes]]是什么

问题描述:

我正在使用redux做出反应。这使得调度可用作组件中的道具。所以当我 console.log(this.props)时,我会在日志下的dispatch键中看到以下对象。

I am using redux with react. This makes dispatch available as props in component. So when I console.log(this.props) I see following object in log under dispatch key.

[[Scopes]]: Scopes[5]
   0:Closure
   1:Closure
   2:Closure (createThunkMiddleware)
   3:Closure
   4:Global

有人可以解释这是什么?

Can someone explain what is this ?

[[Scopes]] 是Chrome开发人员的私有财产工具在内部添加和使用,在C ++中,此处来源。它显示函数范围内的变量,即可以从该函数访问哪些变量。

[[Scopes]] is a private property that Chrome developer tools add and use internally, in C++, here in the source. It displays the variables that are in the scope of a function, i.e. which variables can be accessed from that function.

例如:

function a() {
  var foo = 'foo';
  var obj = {
    bar: function () {
      return foo;
    }
  };
  console.log(obj);
}
a();

这里,附加到属性的函数 obj.bar 在其范围内有变量 foo ,所以当我们检查 [[Scopes]] obj.bar 我们看到类似

Here, the function that is attached to property obj.bar has variable foo in its scope, so when we inspect the [[Scopes]] propety of obj.bar we see something like

[[Scopes]]: Scopes[2]
0: Closure (a)
  foo: "foo"
1: Global
  (all global variables)






您可以在控制台中手动检查这些属性,这可能有助于调试,但您不能使用JavaScript访问它们,您不应该在应用程序代码中关注它们。


You can manually inspect these properties in the console, which might be helpful for debugging, but you can't access them using JavaScript and you shouldn't care about them in your application code.

另请参阅: SO - 以编程方式访问功能位置