[英]ExecJS::ProgramError: SyntaxError: Reserved word “function”
In our rails rfq.js.coffee, we only have a simple js code: 在我们的rails rfq.js.coffee中,我们只有一个简单的js代码:
$(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. 但是,此代码会导致错误,指出第一行中的function()是保留字。 Since the first line is basically a jquery
$(document).ready(function () {})
, we have no clue why this error shows up. 由于第一行基本上是一个jquery
$(document).ready(function () {})
,我们不知道为什么会出现这个错误。 Any thoughts about it? 有什么想法吗? Thanks so much.
非常感谢。
You can't use standard JS like that in a Coffeescript file. 您不能在Coffeescript文件中使用标准JS。 Either rename the file to
rfq.js
, or convert it to coffeescript: 将文件重命名为
rfq.js
,或将其转换为coffeescript:
$ ->
$('#need_report').change ->
if $(this).val()
$('#report_language').hide()
You can embed regular javascript by surrounding the code with back-ticks "`". 你可以通过用反向标记“`”包围代码来嵌入常规的javascript。 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
http://coffeescript.org/#embedded
也许您将JavaScript代码写入扩展名为.coffee
文件中,您可以使用js2.coffee将代码从JavaScript转换为CoffeeSecript
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.