Arrays of Literals in Coffeescript

coffeescript

Solution

This has been the one thing that every CoffeeScript developer seems to run into.

I'm afraid it's all we have for now. The only other alternative I can think of is:

[
  { name: 'david', value: 'blue' }
  { name: 'harold', value: 'orange' }
]

… but it's far from ideal itself.

If anyone wanted to suggest an alternate, concise and CS-y syntax, I'd be happy to try to implement it in the parser and make a pull request for it. I'd love to have better than this.

Problem

When creating an array of literals in JS: ``` [{ name: 'david', value: 'blue' }, { name: 'harold', value: 'orange' }] ``` The only way I can see of writing this in Coffeescript is: ``` [ name: 'david' value: 'blue' , name: 'harold' value: 'orange' ] ``` To me this is pretty ugly, that "floating" comma doesn't really sit well. Are there any alternative syntaxes for this? I am aware you can continue to use a JS-style approach from within Coffeescript but I was hoping for something more concise.

Original source