More Related Content Similar to CoffeeScript (20) More from Ryo Maruyama (15) CoffeeScript1. CoffeeScript
2012/01/18
h13i32maru@Twitter
maruyama-r@KLab
2. 自己紹介
• 丸山 亮(h13i32maru) 最近はJSを触ってます
• KLab株式会社所属
32 http://blog.h13i32maru.jp
http://twitter.com/h13i32maru
https://www.facebook.com/ryo.maruyama
https://github.com/h13i32maru
9. 関数
func = (arg1, arg2) -> arg1 * arg2
func = (arg1, arg2) ->
x = arg1 * arg2
x * x
11. 内包表記
eat food for food in ['toast', 'cheese', 'wine']
countdown = (num * num for num in [10..1])
yearsOld = max: 10, ida: 9, tim: 11
ages = for child, age of yearsOld
"#{child} is #{age}"
12. 配列のスライスとレンジ
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
middle = numbers[3..6]
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
numbers[3..6] = [-3, -4, -5, -6]
13. 比較
if x is 0
if y isnt 100
cholesterol = 127
healthy = 200 > cholesterol > 60
15. クラスと継承
class Animal
constructor: (@name) ->
move: (meters) ->
alert @name + " moved #{meters}m."
class Snake extends Animal
move: ->
alert "Slithering..."
super 5
16. 展開代入
theBait = 1000
theSwitch = 0
[theBait, theSwitch] = [theSwitch, theBait]
17. 関数束縛
Account = (customer, cart) ->
@customer = customer
@cart = cart
$('.shopping_cart').bind 'click', (event) =>
@customer.purchase @cart
19. 全てが式
i = 0
res = while i isnt 10
i++
i * i
#1,4,9,16,25,36,49,64,81,100
alert res