【发布时间】:2019-02-18 15:24:06
【问题描述】:
使用 ES2018 是否有更强大的方法来创建此主题列表(我想要的是自动生成的数字)。
const Topics = {
NullTopic: 0,
simActorStateTest: 1,
navActorStateTest: 2,
simTelemetryVenom11: 3,
navTelemetryVenom11: 4,
simTelemetryVenom12: 5,
navTelemetryVenom12: 6,
scenarioStart: 7,
scenarioEnd: 8,
}
【问题讨论】:
-
我会写一个函数来接受一个选择数组并为你填充一个对象。
-
看看this
-
或者在你可以使用整数的时候不要使用use symbols(也可以是here)
-
它正在与一个在 Google FlatBuffer 中发送整数的 C++ 程序进行通信。
-
["string1", "string2", "string3"].reduce((r, s, i) => (r[s] = i, r), {})
标签: javascript