rails, getting syntax error with coffee script

前端 未结 2 1889
终归单人心
终归单人心 2021-02-15 14:29

i am trying to do an autocomplete feature in rails using the jquery ui library. however i keep getting syntax errors \"Syntax Error: reserved word \"function\" on line ...\"

相关标签:
2条回答
  • 2021-02-15 15:20

    If you want to embed javascript within a coffeescript file, you can do so using backticks:

    jQuery ->
      `function abc() { return 123; }  // js syntax here`
    

    See here: http://coffeescriptcookbook.com/chapters/syntax/embedding_javascript

    This is pretty confusing, though, so it is generally a better idea to convert the code to coffeescript, in which case you can use the js2coffee.org converter as DanS suggested.

    0 讨论(0)
  • 2021-02-15 15:21

    Only the first line is coffeescript; the rest is normal javascript.

    Try using this converter:

    http://js2coffee.org/

    $(function() {}); becomes $ ->

    0 讨论(0)
提交回复
热议问题