ExecJS::ProgramError: SyntaxError: 保留字“函数”
在我们的 Rails rfq.js.coffee 中,我们只有一个简单的 js 代码:
$(function() {
$('#need_report').change(function(){
if ($(this).val() == true) {
$('#report_language').hide();
} // end if
}); // end change()
}); // end ready(function)
但是此代码会导致错误,指出第一行中的 function() 是保留字。由于第一行基本上是 jquery $(document).ready(function () {})
,因此我们不知道为什么会出现此错误。有什么想法吗?非常感谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您不能在 Coffeescript 文件中使用标准 JS。将文件重命名为 rfq.js,或将其转换为 Coffeescript:
You can't use standard JS like that in a Coffeescript file. Either rename the file to
rfq.js
, or convert it to coffeescript:您可以通过用反引号“`”包围代码来嵌入常规 JavaScript。我希望它也像其他解析语言一样工作......我花了很多不必要的调试和搜索来解决这个问题。 http://coffeescript.org/#embedded
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
也许您将 JavaScript 代码写入扩展名为
.coffee
的文件中,您可以使用 js2.coffee 来将您的代码从 JavaScript 转换为 CoffeeSecriptMaybe you wrote JavaScript code into file with extension
.coffee
you can use js2.coffee to convert your code from JavaScript to CoffeeSecript