保留字“函数”

Reserved word “function”

我正在尝试进行无限滚动,但出现此错误?

ExecJS::RuntimeError in Pages#profile Showing C:/Users/mojo/rails/railsapp/apps/app/views/layouts/application.html.erb where line #6 raised: SyntaxError: [stdin]:4:19: reserved word "function"

post.coffee

   $(document).ready(function() {
      if ($('.pagination').length) {
        $(window).scroll(function() {
          var url = $('.pagination .next_page').attr('href');
          if (url && $(window).scrollTop() > $(document).height() - $(window).height() - 50) {
            $('.pagination').text("Please Wait...");
            return $.getScript(url);
          }
        });
        return $(window).scroll();
      }
    });

Javascript 和 coffeescript 语法不相互兼容。

在您的例子中,文件内容是 javascript,其中文件名表明它是一个 coffeescript 文件,因此 sprockets 试图将其解析为 coffeescript。

您可以将 post.coffee 重命名为 post.js 来解决这个问题。