ExecJS::ProgramError: SyntaxError: 保留字“函数”

发布于 2024-12-29 09:26:16 字数 404 浏览 2 评论 0原文

在我们的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

ゃ懵逼小萝莉 2025-01-05 09:26:16

您不能在 Coffeescript 文件中使用标准 JS。将文件重命名为 rfq.js,或将其转换为 Coffeescript:

$ ->
  $('#need_report').change ->
    if $(this).val()
      $('#report_language').hide()

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()
我ぃ本無心為│何有愛 2025-01-05 09:26:16

您可以通过用反引号“`”包围代码来嵌入常规 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

椒妓 2025-01-05 09:26:16

也许您将 JavaScript 代码写入扩展名为 .coffee 的文件中,您可以使用 js2.coffee 来将您的代码从 JavaScript 转换为 CoffeeSecript

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文