Can you explain this JavaScript syntax (variable extrapolation)?

I just saw something that I had not seen before and can’t find an explanation of what it really is ... not in the ES5.1 standard and the ES6 project, nor in support of Mozilla ES6 .

Please explain technically what is happening (anonymous object, anonymous block?) And give some link to a section in the ES standard or to another resource that explains this.

Context is a firefox extension.

const // var also works here it seems
{
      classes    : Cc
    , interfaces : Ci
    , utils      : Cu

} = Components

It creates the variables Cc, Ci, Cu in the current area. This is a kind of counter intuitive, since it looks like an anonymous object, but then one would expect the names of the properties on the left and the values ​​on the right ...

: https://developer.mozilla.org/en-US/Add-ons/Overlay_Extensions/XUL_School/JavaScript_Object_Management

update: (). , .

+4
2

ES6 Destructuring. .

Components :

{classes: 'asdf', interfaces: 'qwer', utils: `zxcv`}

( const, ).

Cc // 'asdf'
Ci // 'qwer'
Cu // 'zxcv'
+6

Mozilla:

Components.classes Components.interfaces, :

const Cc = Components.classes, Ci = Components.interfaces;

var os = Cc["@mozilla.org/observer-service;1"] .getService(Ci.nsIObserverService);

, , - , ES6.

+1

Source: https://habr.com/ru/post/1569015/


All Articles