redux 的 dispatch() 中的 [[Scopes]] 是什么 [英] What is [[Scopes]] in dispatch() of redux

查看:30
本文介绍了redux 的 dispatch() 中的 [[Scopes]] 是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 redux 和 react.这使得 dispatch 作为组件中的 props 可用.因此,当我 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 - 以编程方式访问函数位置.

这篇关于redux 的 dispatch() 中的 [[Scopes]] 是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆