LoginSignup
0
0

More than 5 years have passed since last update.

CoffeeScript使ってみた

Posted at

参考

準備

インストール
sudo apt-get install coffeescript
a.coffee
nums = [1, 2, 3, 4, 5]
if nums[3] is 3
  window.alert '一致' 
else
  window.alert nums[3]

変換

a.jsが出来る
coffee -c a.coffee
a.js
// Generated by CoffeeScript 1.4.0
(function() {
  var nums;

  nums = [1, 2, 3, 4, 5]; 

  if (nums[3] === 3) {
    window.alert('一致');
  } else {
    window.alert(nums[3]);
  }

}).call(this);

グローバル変数

  • グローバル変数にしたい場合、先頭に@付ける
a.coffee
@nums = nums
a.js
   this.nums = nums;

他でnumsにアクセスが出来ます。
グローバル変数に展開されないように書けるので良いかと。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0