ExecJS::ProgramError: SyntaxError: Reserved word “

2019-02-16 04:05发布

In our rails rfq.js.coffee, we only have a simple js code:

$(function() {
  $('#need_report').change(function(){
    if ($(this).val() == true) {
      $('#report_language').hide();
    }  // end if
  });  // end change()
});  // end ready(function)

However this code causes an error saying that function() in first line is a reserved word. Since the first line is basically a jquery $(document).ready(function () {}), we have no clue why this error shows up. Any thoughts about it? Thanks so much.

3条回答
淡お忘
2楼-- · 2019-02-16 04:31

Maybe you wrote JavaScript code into file with extension .coffee you can use js2.coffee to convert your code from JavaScript to CoffeeSecript

查看更多
来,给爷笑一个
3楼-- · 2019-02-16 04:41

You can't use standard JS like that in a Coffeescript file. Either rename the file to rfq.js, or convert it to coffeescript:

$ ->
  $('#need_report').change ->
    if $(this).val()
      $('#report_language').hide()
查看更多
爷的心禁止访问
4楼-- · 2019-02-16 04:55

You can embed regular javascript by surrounding the code with back-ticks "`". I wish it worked like the other parsing languages as well...it took me lot's of unnecessary debugging and searching to figure that out. http://coffeescript.org/#embedded

查看更多
登录 后发表回答