gpt4 book ai didi

Javascript:这个 javascript 功能是什么

转载 作者:行者123 更新时间:2023-11-29 16:42:44 25 4
gpt4 key购买 nike

我正在阅读一个 React 示例项目。这是 reducer 代码:

export const COUNTER_INCREMENT = 'COUNTER_INCREMENT';
export const COUNTER_DOUBLE_ASYNC = 'COUNTER_DOUBLE_ASYNC';

// ------------------------------------
// Action Handlers
// ------------------------------------
const ACTION_HANDLERS = {
[COUNTER_INCREMENT] : (state, action) => state + action.payload,
[COUNTER_DOUBLE_ASYNC] : (state, action) => state * 2,
};

我不知道 ACTION_HANDLERS 是什么意思。这个javascript有什么特点呢?

谢谢

最佳答案

ACTION_HANDLERS 只是一个带有 Computed property names 的 JavaScript 对象.

Starting with ECMAScript 2015, the object initializer syntax also supports computed property names. That allows you to put an expression in brackets [], that will be computed as the property name. This is symmetrical to the bracket notation of the property accessor syntax, which you might have used to read and set properties already

对于每种操作类型,它都有一个 arrow function .

关于Javascript:这个 javascript 功能是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43950691/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com