javascript - coffeescript: suppress "ReferenceError" - Stack Overflow

Currently working through this tutorial on using Backbone.js with coffeescript.Leveraging the following

Currently working through this tutorial on using Backbone.js with coffeescript.

Leveraging the following index.html file:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>CoffeeScript, Meet Backbone.js: Part N</title>
  <link rel="stylesheet" href="style.css">
  <script src=".6.1/jquery.min.js"></script>
  <script src=".js"></script>
  <script src=".js/1.1.6/underscore-min.js"></script>
  <script src=".js/0.3.3/backbone-min.js"></script>
  <script type="text/javascript" src="./index.js"></script>

</head>
<body>
  <header>
    <h1>CoffeeScript, Meet Backbone.js: Part 1</h1>
  </header>
</body>


</html>

which loads an index.js file after loading Backbone, jQuery, etc from a cdn. Hoping to work within a script.coffee file that I'd like to have automatically pile into the script.js file loaded by index.html above by running something like coffee script.coffee -c -w.

Trouble is, I'm getting ReferenceErrors when I try to run the above mand on the following script.coffee file:

jQuery ->

  class ListView extends Backbone.View

    el: $ 'body'

    initialize: ->

      _.bindAll @
      @render()

    render: ->
      $(@el).append '<ul><li>Hello, Backbone!</li></ul>'

  list_view = new ListView

For instance:

ReferenceError: jQuery is not defined
...

because, clearly, jQuery is being loaded in the index.html file.

Is there a way to suppress the error reporting from the coffeescript piler so that it just converts the code without the error?

Currently working through this tutorial on using Backbone.js with coffeescript.

Leveraging the following index.html file:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>CoffeeScript, Meet Backbone.js: Part N</title>
  <link rel="stylesheet" href="style.css">
  <script src="https://ajax.googleapis./ajax/libs/jquery/1.6.1/jquery.min.js"></script>
  <script src="http://ajax.cdnjs./ajax/libs/json2/20110223/json2.js"></script>
  <script src="http://ajax.cdnjs./ajax/libs/underscore.js/1.1.6/underscore-min.js"></script>
  <script src="http://ajax.cdnjs./ajax/libs/backbone.js/0.3.3/backbone-min.js"></script>
  <script type="text/javascript" src="./index.js"></script>

</head>
<body>
  <header>
    <h1>CoffeeScript, Meet Backbone.js: Part 1</h1>
  </header>
</body>


</html>

which loads an index.js file after loading Backbone, jQuery, etc from a cdn. Hoping to work within a script.coffee file that I'd like to have automatically pile into the script.js file loaded by index.html above by running something like coffee script.coffee -c -w.

Trouble is, I'm getting ReferenceErrors when I try to run the above mand on the following script.coffee file:

jQuery ->

  class ListView extends Backbone.View

    el: $ 'body'

    initialize: ->

      _.bindAll @
      @render()

    render: ->
      $(@el).append '<ul><li>Hello, Backbone!</li></ul>'

  list_view = new ListView

For instance:

ReferenceError: jQuery is not defined
...

because, clearly, jQuery is being loaded in the index.html file.

Is there a way to suppress the error reporting from the coffeescript piler so that it just converts the code without the error?

Share Improve this question edited Nov 30, 2013 at 4:40 fox asked Nov 30, 2013 at 4:18 foxfox 16.6k22 gold badges59 silver badges85 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 10

The options must go before the file, e.g.:

coffee -cw script.coffee

Otherwise, it will try to run script.coffee right then and there as a Node.js script, passing it the options -c and -w. That's not what you want; if you want the CoffeeScript piler to get the options, it's got to be before the file name.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744760621a4592153.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信