2011/10/23

CoffeeScript

CoffeeScript is just JavaScript!

CoffeeScript 有自己獨特的語法(類似 Python 混搭 Ruby),
編寫好的 CoffeeScript 檔,透過 CoffeeScript Compiler 可以編譯成通用的 Javascript

[使用 apt-get 安裝 CoffeeScript Compiler]
sudo apt-get install python
sudo apt-get install openssh-server libssl-dev
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:chris-lea/node.js
sudo add-apt-repository ppa:gias-kay-lee/coffeescript
sudo apt-get update
sudo apt-get install nodejs
sudo apt-get install coffeescript

[使用 NPM 安裝 CoffeeScript Compiler]

要使用 NPM 需要先安裝好 Node.js 環境,請參考:
http://zx-1986.blogspot.com/2011/10/nodejs.html

然後執行:
sudo npm install -g coffee-script

[編譯安裝 CoffeeScript Compiler]
git clone https://github.com/jashkenas/coffee-script.git
cd coffee-script
sudo bin/cake install

[編譯 .coffee 檔產生 .js 檔]
# Compile a directory tree of .coffee files into a parallel tree of .js, in lib:
coffee -o lib/ -c src/

# Watch a file for changes, and recompile it every time the file is saved:
coffee --watch --compile experimental.coffee

# Concatenate a list of files into a single script:
coffee --join project.js --compile src/*.coffee

# Print out the compiled JS from a one-liner:
coffee -bpe "alert i for i in [0..10]"

# Start the CoffeeScript REPL(read-eval-print loop):
coffee

Reference:
http://upgrade2rails31.com/coffee-script
http://jashkenas.github.com/coffee-script

沒有留言:

張貼留言