rails, getting syntax error with coffee script

前端 未结 2 1879
终归单人心
终归单人心 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.

提交回复
热议问题