【问题标题】:What is [[Scopes]] in dispatch() of reduxredux 的 dispatch() 中的 [[Scopes]] 是什么
【发布时间】:2018-01-12 09:20:07
【问题描述】:

我正在使用带有 react 的 redux。这使得 dispatch 可以作为组件中的 props 使用。所以当我console.log(this.props) 我在调度键下的日志中看到以下对象。

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

有人能解释一下这是什么吗?

【问题讨论】:

  • 一个很奇怪的输出?
  • 完整日志dispatch: function (action) arguments: (...) caller: (...) length:1 name: "" prototype: Object __proto__:function () [[FunctionLocation]] : index.js?f248:9 [[Scopes]]: Scopes[5] errorText:undefined }
  • 我不明白这个问题 :-) 你没有 dispatch in props 吗?
  • 是的,我有..就是这样。它工作正常..我只想知道这个日志的含义是什么。什么是 [[Scopes]] 及其闭包。

标签: javascript reactjs google-chrome redux react-redux


【解决方案1】:

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

例如:

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

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

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

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

另请参阅:SO - Access function location programmatically

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-31
    • 1970-01-01
    • 2018-11-03
    • 2018-10-26
    • 2018-05-09
    • 2017-10-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多