1

根据文档,您可以使用方括号进行成员访问。但是,当我尝试使用变量执行此操作时,会导致以下错误。

a = "ABC"
b = "DEF"

//This works
calc = (r) => r.ABC - r.DEF

calc = (r) => r["ABC"] - r["DEF"]

//However, I can't find a way to access the members using the variables

calc = (r) => r["${a}"] - (r["${b}"]
> type error @8:23-8:36: expected int but found string


calc = (r) => r[a] - r[b]
> type error @8:23-8:31: expected int but found string

如何使用变量访问成员?

4

1 回答 1

1

抱歉 - 我引用的相同文档有答案:

无法使用任意表达式访问记录的属性。

于 2020-11-18T08:10:04.163 回答