0

Q: Does anyone know what this JavaScript ES6 feature is called? It's a technique of applying a prefix to identified names. Like this:

var { Router,
Route,
IndexRoute,
IndexLink,
hashHistory,
Link } = ReactRouter;

It saves me having to write long code. Example:

I can write this in React:

<Route path="/acc"          component={CLAccounts} />
<Route path="/acc/:year"        component={CLAccounts} />
<Route path="/acc/:year/:month"     component={CLAccounts} />

Instead of this:

<ReactRouterRoute path="/acc"           component={CLAccounts} />
<ReactRouterRoute path="/acc/:year"     component={CLAccounts} />
<ReactRouterRoute path="/acc/:year/:month"  component={CLAccounts} />
Milton Valler
  • 53
  • 1
  • 5
  • https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment – Mottie May 06 '17 at 16:35
  • 1
    This has nothing to do with "prefixes". The proper "long" syntax would be `ReactRouter.Route` (not `ReactRouterRoute`), which is simple property access – Bergi May 06 '17 at 16:37
  • It was in an article expressly to show how to save typing. ie: prefixing. Maybe it's just using the syntax in a different way. – Milton Valler May 08 '17 at 15:34

1 Answers1

0

This is called destructuring. It's super useful!!

Read more here

jacoballenwood
  • 2,787
  • 2
  • 24
  • 39
  • Thanks. Destructuring seems to have more to do with breaking apart an array into separate vars. There's no data here per se, just a way to prefix variables. Anyway, very useful to save typing. – Milton Valler May 08 '17 at 15:33