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

查看:123
本文介绍了初学者:在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天全站免登陆