categories = {{"code": "zzz", "title": "Electronics"}, {"code": "yyy", "title": "Cars"}};
That's my JavaScript. What's the equivalent CoffeeScript?
Braces are optional in CoffeeScript, you can have either this:
categories = [
code : 'zzz'
title : 'Electronics'
,
code : 'yyy'
title : 'Mechanics'
]
(notice the unindented comma) or the more obvious:
categories = [
{
code : 'zzz'
title : 'Electronics'
}, // comma optional
{
code : 'yyy'
title : 'Mechanics'
}
]
First of all, I think your JavaScript should look like this:
categories = [{"code": "zzz", "title": "Electronics"}, {"code": "yyy", "title": "Cars"}];
You do want an array, correct? Then the CoffeeScript is, well, exactly the same (without the trailing semicolon but that's also optional in JavaScript):
categories = [{"code": "zzz", "title": "Electronics"}, {"code": "yyy", "title": "Cars"}]
There's a "TRY COFFEESCRIPT" button at the top of the Github CoffeeScript page that you might find useful for things like this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With