in CoffeeScript, how can I use a variable as a key in a hash?

后端 未结 6 2014
野趣味
野趣味 2021-01-07 16:00

eg:

\"wtf\"

So:

foo = \"asdf\"
{foo: \"bar\"}
eval foo

# how do I g         


        
6条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-07 16:49

    Try this:

    foo = "asdf"
    
    eval "var x = {#{foo}: 'bar'}"
    alert(x.asdf)
    

提交回复
热议问题