首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ngrx 8 createAction语法

ngrx 8 createAction语法
EN

Stack Overflow用户
提问于 2020-10-14 14:56:37
回答 1查看 62关注 0票数 0

我现在正在学习ngrx角。我对ngrx语法没有什么混淆。

我知道下面的语法箭头函数只是返回"customer“对象。

代码语言:javascript
复制
export const addCustomer = createAction(

   '[Customer] Add Customer',
     (customer: Customer) => {customer}
);

但这是什么语法?下面的圆括号"({customer})“是什么意思?我是不是错过了ES6的什么东西?

代码语言:javascript
复制
export const addCustomer = createAction(

   '[Customer] Add Customer',
     (customer: Customer) => ({customer})
);
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-10-14 22:44:39

(customer: Customer) => ({customer})是一个返回对象{ customer: customer }的函数。

要理解它,您需要熟悉两个概念。

  1. () => ({})() => { return {}; }.
  2. { customer }一样,{ customer: customer }也是一样的。类型记录允许在情况属性和变量名称重合(例如,customer键和customer变量重合时)这样的快捷方式。
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64356079

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档