-1

quick question. What is wrong with this?

content_key = $('#login_ConfigPostcontentkey').val()
content_value = $('#login_ConfigPostcontentvalue').val()
content = { #{content_key} : content_value }

When I run it I get:

unmatched OUTDENT

This is a unique case for this is in CoffeeScript with formatting needs.

TheAce
  • 122
  • 1
  • 16

1 Answers1

0

You can't use string interpolation (using #{ }) as the key of an object property. In raw Javascript, there is no way to use curly-braced object notation to reference a key name variable. It has to be a string. Therefore, coffeescript can't compile that code.

If you use square-bracket object notation, it will work. Change your last line:

content[content_key] = content_value 
carlbenson
  • 3,177
  • 5
  • 35
  • 54
  • But I am using CoffeeScript as my language. Does that change anything? – TheAce May 19 '14 at 16:18
  • Coffeescript compiles to Javascript, meaning that the underlying code has to work in Javascript. So unfortunately, in this case, there is no other way to do what you want to do. – carlbenson May 19 '14 at 16:19
  • But all I need is to have content be the combination of variable content_key and content_value? That is not possible? – TheAce May 19 '14 at 16:20