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

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

eg:

\"wtf\"

So:

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

# how do I g         


        
6条回答
  •  一整个雨季
    2021-01-07 16:58

    For anyone that finds this question in the future, as of CoffeeScript 1.9.1 interpolated object literal keys are supported!

    The syntax looks like this:

    myObject =
      a: 1
      "#{ 1 + 2 }": 3
    

    See https://github.com/jashkenas/coffeescript/commit/76c076db555c9ac7c325c3b285cd74644a9bf0d2

提交回复
热议问题