CoffeeScript メモ その1
『 CoffeeScriptファーストガイド』を読んでのメモ その1。
- CoffeeScriptインストール
sudo npm install -g coffee-script- eオプションを使うと引数に書いたプログラムを直接実行できる
coffee -e "console.log 'hello, world'"
=> hello, world- pオプションをつけるとコンパイル後のjsを表示できる
coffee -pe "console.log 'hello, world'"
=> (function() {
console.log('hello, world');
}).call(this);- wオプションをつけるとソースの変更を監視して自動コンパイルできる
coffee -cw hello.coffee- oオプションをつけると別ディレクトリにjsを保存できる
以下のようなディレクトリ構造になっている場合
src/
hello.coffee
sample.coffee
lib/
hello.js
sample.jscoffee -cw -o lib srcsrcディレクトリ以下に変更がある度に、libにjsを出力する
- 関数の書き方
say = (text) ->
console.log text
say "hello"
=> hello- コメントについて
# コメントは#で書く。コンパイル後のjsからは除去される
###
コンパイル後も残したい場合は###で囲う
###