初学者:Redux 中的 const 定义令人困惑 [英] beginner's: const definition in Redux confusing

查看:11
本文介绍了初学者:Redux 中的 const 定义令人困惑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这个 Redux 入门课程中https://egghead.io/lessons/javascript-redux-store-methods-getstate-dispatch-and-subscribe?series=getting-started-with-redux,主持人说下面两行是一样的

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;

我刚刚搜索了 ES6 const 文档,它并没有完全回答我的问题,这两行如何相同?

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

推荐答案

这与const(只是定义常量的一种方式)无关,而是与对象解构.

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

所以这些都是相同的:

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

const { createStore: createStore } = Redux;这一行中,第一个createStore定义了Redux要获取的属性.第二个 createStore 定义了在声明后可用的名称.

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.

另外,在 ES6 中定义像 { name: name } 这样的对象可以缩短为 { name }.

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

这篇关于初学者:Redux 中的 const 定义令人困惑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆