Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
178 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 Reply

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...