Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

In this introductory course of Redux https://egghead.io/lessons/javascript-redux-store-methods-getstate-dispatch-and-subscribe?series=getting-started-with-redux, the presenter says that the following two lines are identical

const { createStore } = Redux;
var createStore = Redux.createStore;

I've just searched for ES6 const documentation, and it does not quite answer my question, how are these two lines identical?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
162 views
Welcome To Ask or Share your Answers For Others

1 Answer

This is not related to const (which is just a way to define a constant), but instead to object destructuring.

So these are all identical:

var createStore = Redux.createStore;
const { createStore: createStore } = Redux;
const { createStore } = Redux;

In the line const { createStore: createStore } = Redux;, the first createStore defines the property of Redux to get. The second createStore defines the name under which is available after the declaration.

In addition, in ES6 defining objects like { name: name } can be shortened to { name }.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...