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

Categories

0 votes
165 views
in Technique[技术] by (71.8m points)

javascript - beginner's: const definition in Redux confusing

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

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

1 Answer

0 votes
by (71.8m points)

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 }.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...