在这个Redux https://egghead.io/lessons/javascript-redux-store-methods-getstate-dispatch-and-subscribe?series=getting-started-with-redux的入门课程中,演示者说下面两行是相同的
const { createStore } = Redux;
var createStore = Redux.createStore;我刚刚搜索了ES6 const文档,它没有完全回答我的问题,这两行是如何相同的?
发布于 2016-03-30 07:54:23
这与const无关(这只是定义常量的一种方法),而是与object destructuring有关。
所以这些都是相同的:
var createStore = Redux.createStore;
const { createStore: createStore } = Redux;
const { createStore } = Redux;在const { createStore: createStore } = Redux;行中,第一个createStore定义要获取的Redux属性。第二个createStore定义声明后可用的名称。
此外,在ES6中,定义像{ name: name }这样的对象可以缩短为{ name }。
https://stackoverflow.com/questions/36302741
复制相似问题