2

I see this in facebook's fixed-data-table reactjs ui example code (written in ECMAScript6):

const {Table, Column, Cell} = FixedDataTable;

I used const before, but all the ECMA6 documentation and reactjs that I can find does not explain what the code snippet above exactly does. The syntax doesn't make sense to me, yet it clearly is important because without it I can't use FixedDataTable react class, and the snippet below does not render the UI:

                <Table rowHeight={50}
                       rowsCount={rows.length}
                       width={500}
                       height={500}
                       headerHeight={50}>
                    <Column header={<Cell>Col 1</Cell>}
                      cell={<Cell>Column 1 static content</Cell>}
                      width={200}
                    />
                </Table>
Echiban
  • 849
  • 2
  • 11
  • 21
  • 1
    Possible duplicate of [Javascript object bracket notation on left side to assign](http://stackoverflow.com/questions/26999820/javascript-object-bracket-notation-on-left-side-to-assign) – Felix Kling Dec 13 '15 at 17:33

2 Answers2

1

This is Destructuring assignment (Object destructuring, actually).

After that line Table is FixedDataTable.Table, Column is FixedDataTable.Column and Cell is FixedDataTable.Cell. const makes these variables read-only.

It's equivalent to:

const Table = FixedDataTable.Table,
      Column = FixedDataTable.Column,
      Cell = FixedDataTable.Cell;
vaultah
  • 44,105
  • 12
  • 114
  • 143
  • 1
    Thanks for that. I didn't know about Destructuring as a concept. Haven't worked with Javascript in depth for some time and ES6 is taking me some time to get used to. – Echiban Dec 13 '15 at 10:25
0

Take a look at Destructuring assignment. FixedDataTable is probably an object with properties Table, Column and Cell.

What it actually does:

const Table = FixedDataTable.Table;
const Column = FixedDataTable.Column;
const Cell = FixedDataTable.Cell;
madox2
  • 49,493
  • 17
  • 99
  • 99