データ手続き型
procedural.coffee
beats = (you, opponent)->
if you is 'rock'
if opponent is 'scissors'
return true
else
return false
else if you is 'paper'
if opponent is 'rock'
return true
else
return false
else if you is 'scissors'
if opponent is 'paper'
return true
else
return false
else
throw new Error("your hand is unexpected: #{you}")
you = 'rock'
opponent = 'paper'
console.log beats(you, opponent)
console.log beats(opponent, you)
オブジェクト指向
oo.coffee
class Rock
beats: (hand)->
return hand instanceof Scissors
class Paper
beats: (hand)->
return hand instanceof Rock
class Scissors
beats: (hand)->
return hand instanceof Paper
you = new Rock
opponent = new Paper
console.log you.beats(opponent)
console.log opponent.beats(you)
論理型
janken.pro
beats(rock, scissors).
beats(paper, rock).
beats(scissors, paper).
関数型
だれか...