1

I'm watching the Redux videos found here: http://redux.js.org/ and I'm seeing the following pattern:

const { Component } = React;

How does this work?

c4urself
  • 4,207
  • 21
  • 32
  • what do you mean? it works because the language/transpiler/browser allow such syntax? – Bryan Chen Oct 18 '16 at 03:27
  • 1
    It's [object descructuring assignment](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#Object_destructuring). – nnnnnn Oct 18 '16 at 03:30

1 Answers1

2

This is called Object Destructuring. The result of the above statement is that a variable called Component now exists. NOTE: If you're familiar with Python it's a lot like tuple-unpacking.

var foo = {a: 1, b: 2};
var {a, b} = foo;

var bar = {c: 3, d: 4};
var {c} = bar;

console.log(a) => 1
console.log(b) => 2
console.log(c) => 3
c4urself
  • 4,207
  • 21
  • 32