Coffeescript编译错误

时间:2013-08-18 17:13:56

标签: coffeescript

我刚刚安装了Coffeescript并尝试了一个测试编译,但它总是让我失去了愚蠢的错误,Coffeescript只在使用Coffeescript语法时才能正确编译?

因为如果是,那么我理解错误。enter image description here

concDev.js内容:

/*! ProjectName 2013-08-18 06:08:39 */
$(function() {

  // Avoid `console` errors in browsers that lack a console.
  (function() {
      var method;
      var noop = function () {};
      var methods = [
          'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',
          'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log',
          'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd',
          'timeStamp', 'trace', 'warn'
      ];
      var length = methods.length;
      var console = (window.console = window.console || {});

      while (length--) {
          method = methods[length];

          // Only stub undefined methods.
          if (!console[method]) {
              console[method] = noop;
          }
      }
  }());

});
// New file
$(function() {

  // Handler for .ready() called.

});

1 个答案:

答案 0 :(得分:2)

你不能在Coffeescript中使用C风格的评论。

/*! Project Name ...*/

应该是这个

# Project Name ...

更一般地说,如果您使用的是Coffeescript编译器,则需要有效的coffeescript语法,并且不能混合使用JS和coffeescript文件。

更新

您正在尝试将JS文件传递给coffeescript编译器。咖啡编译器接受coffeescript文件,并将其编译为JS文件。你在Coffeescript中的文件看起来像这样:

#! ProjectName 2013-08-18 06:08:39 */
$ ->

  # Avoid `console` errors in browsers that lack a console.
  do  ->
      noop = -> null
      methods = [
          'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',
          'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log',
          'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd',
          'timeStamp', 'trace', 'warn'
      ]
      length = methods.length
      console = window.console = window.console || {}

      while length--
          method = methods[length]
          # Only stub undefined methods.
          if !console[method]
              console[method] = noop;
// New file
$ ->
  #Handler for .ready() called.

如果你真的需要在你的coffeescript文件中加入一些JS,你可以使用这样的反引号嵌入它

a = `(function() x{ return 2;})()`
相关问题