Coffeescript 简明教程

CoffeeScript - Environment

CoffeeScript 最新版本的编译器是用 CoffeeScript 本身编写的。要在没有浏览器的情况下在你的系统中运行 CoffeeScript 文件,你需要一个 JavaScript 运行时。

The Compiler of the latest versions of CoffeeScript is written in CoffeeScript itself. To run CoffeeScript files in your system without a browser, you need a JavaScript runtime.

Node.js

Node.js 是一个 JavaScript 框架,用于开发网络服务器应用程序。它还充当 JavaScript 和操作系统之间的桥梁。

Node.js is a JavaScript framework which is used to develop network server applications. It also acts as a bridge between JavaScript and the Operating System.

CoffeeScript 的命令行版本作为 Node.js 包分发。因此,要在你的系统中安装 CoffeeScript(命令行),你需要首先安装 node.js。

The command-line version of CoffeeScript is distributed as a Node.js package. Therefore, to install CoffeeScript (command-line) in your system, you first need to install node.js.

Installing Node.js

以下是下载和在你系统中安装 Node.js 的步骤。

Here are the steps to download and install Node.js in your system.

Step 1

访问 nodejs homepage ,并通过单击下面快照中标亮的按钮下载其适用于 Windows 的稳定版本。

Visit the nodejs homepage and download its stable version for windows by clicking on the button hilighted in the snapshot given below.

homepage

Step 2

单击时,一个名为 node-v5.50-x64 的 .msc 文件将下载到你的系统中,运行下载的文件以启动 Node.js 设置。以下为 Node.js 设置向导欢迎页面的快照。

On clicking, a .msc file named node-v5.50-x64 will be downloaded into your system, run the downloaded file to start the Node.js set-up. Here is the snapshot of the Welcome page of Node.js set-up wizard.

click next

Step 3

单击 Node.js 设置向导欢迎页面中的下一步按钮,它将引导你进入最终用户许可协议页面。接受许可协议,然后单击下一步按钮,如下所示。

Click on the Next button in the Welcome page of the Node.js set-up wizard which will lead you to the End-user License Agreement page. Accept the license agreement and click on the Next button as shown below.

license agreement

Step 4

在下一页中,你需要将目标文件夹设置为要安装 Node.js 的路径。将路径更改为所需的文件夹,然后单击下一步按钮。

On the next page, you need to set the destination folder to the path where you want to install Node.js. Change the path to the required folder and click on the Next button.

set destination folder

Step 5

Custom setup 页面中,选择要安装 node.exe 文件的 Node.js 运行时,然后单击下一步。

In the Custom setup page, select the Node.js runtime to install node.exe file and click Next.

custom setup

Step 6

最后,单击安装按钮,它将启动 Node.js 安装。

Finally, click on the Install button which will start the Node.js installation.

click install

单击 Node.js 设置向导的完成按钮,如下所示,以完成 Node.js 安装。

Click on the Finish button of the Node.js set-up wizard as shown below to complete the Node.js installation.

click finish

Installing CoffeeScript

Node.js 为你提供了一个命令提示符 ( Node.js command prompt )。你可以通过在其中输入以下命令来全局安装 CoffeeScript。

Node.js provides you a command prompt (Node.js command prompt). You can install CoffeeScript globally by entering the following command in it.

c:\> npm install -g coffeescript

执行上述命令后,CoffeeScript 将通过生成以下输出安装在你的系统中。

On executing the the above command, CoffeeScript will be installed in your system by producing the following output.

install coffeescript

Verification

可以通过键入以下命令来验证 CoffeeScript 的安装。

You can verify the installation of the CoffeeScript by typing the following command.

c:\> coffee -v

成功安装时,此命令会向你提供 CoffeeScript 版本,如下所示。

On successful installation, this command gives you the version of CoffeeScript as shown below.

verification