最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What is [[Scopes]] in dispatch() of redux - Stack Overflow

programmeradmin1浏览0评论

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 ?

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 ?

Share Improve this question asked Aug 4, 2017 at 12:21 Uchit KumarUchit Kumar 6771 gold badge10 silver badges26 bronze badges 4
  • A very strange output ? – Emrys Myrooin Commented Aug 4, 2017 at 12:45
  • Complete log dispatch: function (action) arguments: (...) caller: (...) length:1 name: "" prototype: Object __proto__:function () [[FunctionLocation]] : index.js?f248:9 [[Scopes]]: Scopes[5] errorText:undefined } – Uchit Kumar Commented Aug 4, 2017 at 12:54
  • I don't understand the question :-) You don't have dispatch in props ? – Emrys Myrooin Commented Aug 4, 2017 at 12:57
  • Yes i have .. and this is it. its working fine.. I just want to know what is the meaning of this log. What is [[Scopes]] and its closure. – Uchit Kumar Commented Aug 4, 2017 at 13:02
Add a comment  | 

1 Answer 1

Reset to default 19

[[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.

For example:

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

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)

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.

See also: SO - Access function location programmatically.

发布评论

评论列表(0)

  1. 暂无评论