javascript - 你如何使用 CoffeeScript ?

标签 javascript html coffeescript

我想在网站中使用coffeescript,但有些东西似乎不起作用。我的 CoffeeScript 位于外部文件中,它链接到 html 文件。我将 CoffeeScript 编译器也链接到了 html 文件。怎么了?

HTML:

<html>
<head>
    <script type="text/javascript" src="coffee-script.js"></script>
    <script src="jquery-1.10.2.min.js"></script>
    <script type='text/coffeescript' src='Test.coffee'></script>
</head>
<body>
</body>
</html>

CoffeeScript :

$->
random = (number) ->
    console.log Math.ceil(Math.random() * number)
    $("body").append(number)


random(2)

最佳答案

在发布之前尝试将您的 Coffeescript 编译为 Javascript:

Once installed, you should have access to the coffee command, which can execute scripts, compile .coffee files into .js, and provide an interactive REPL.

来源:http://coffeescript.org/#usage

关于javascript - 你如何使用 CoffeeScript ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21535371/

相关文章:

javascript - 如何使用 'javascript' 检索完整的客户信息

javascript - 如何在<Provider>中使用另一个<Consumer>?

javascript - 如何找到数组中第二好的?

javascript - 用于编写更简洁代码的 CoffeeScript 资源

javascript - 快乐的验证问题

javascript - NaN 值始终从 JavaScript 返回

javascript - Angular/ typescript : How to get a reference to a class from a string at runtime without importing

javascript - 为什么我节点的样式只会减少不会增加?

javascript - 如何使用 jquery/javascript 在 html 选择选项中填充 javascript 对象值的数据

javascript - 为什么这个循环不会产生我想要的结果?