- CoffeeScript Application Development
- Ian Young
- 361字
- 2021-04-09 23:58:32
Compiling from a CoffeeScript file
Now that you've tried out the CoffeeScript console, let's try compiling a file. The console is great for trying out ideas and rapidly getting feedback from your code, but you'll do most of your work in CoffeeScript files, which you then compile to JavaScript.
Let's start with a very simple CoffeeScript file. CoffeeScript conventionally uses the .coffee
extension, so let's name our file setup.coffee
.
alert "Welcome!"
Now let's compile this file to JavaScript. Run this from your terminal, in the same directory that holds setup.coffee
:
coffee -c setup.coffee
The -c
option tells the coffee
executable that instead of opening a console, you wish to compile a file. You should now have a file in the same directory named setup.js
. This is the result of your compilation. Open it, and you'll see JavaScript code. You might be able to guess what it will look like:
alert("Welcome!");
The CoffeeScript compiler usually creates very readable output (probably more readable than the output of a few programmers you know!). This is a great feature, because it means that if at any time you want to check the compiler's work, or debug, or explore how the compiler achieves something, you can simply open the compiled file in your favorite text editor and read through it. We'll make use of this throughout the book, especially in the next chapter. Be careful though—any changes you make to the JavaScript file will be overwritten the next time you compile. Treat the JavaScript output as read-only.
Tip
While working through the examples, you may see output from your compiler that is slightly different from that printed here. Different versions of CoffeeScript will produce subtle variations in output. These differences are usually superficial, so don't be alarmed. If you compare the two side by side, you will usually be able to find the difference and see that the rest of the code is unchanged.
- WS/BPEL 2.0 for SOA Composite Applications with IBM WebSphere 7
- Illustrator實(shí)例教程:Illustrator 2021(電子活頁微課版)
- UG NX 8.0基礎(chǔ)與實(shí)例教程
- Spring Web Flow 2 Web Development
- UG NX 9.0中文版 基礎(chǔ)教程 (UG工程師成才之路)
- Excel 2016入門與提高
- Blender 3D Architecture, Buildings, and Scenery
- 圖像處理中的數(shù)學(xué)修煉(第2版)
- 24小時學(xué)會PowerPoint 2010
- Unity 3D\2D手機(jī)游戲開發(fā):從學(xué)習(xí)到產(chǎn)品(第4版)
- Vivado從此開始(進(jìn)階篇)
- 高等院校電腦美術(shù)教材:CorelDRAW X7中文版基礎(chǔ)教程
- Word-Excel-PowerPoint 2010三合一辦公應(yīng)用實(shí)戰(zhàn)從入門到精通(超值版)
- Photoshop CC完全自學(xué)教程:從入門到實(shí)踐(全新版)
- Cacti 0.8 Network Monitoring