根据文档,您可以使用方括号进行成员访问。但是,当我尝试使用变量执行此操作时,会导致以下错误。
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
如何使用变量访问成员?