Skip to content

Instantly share code, notes, and snippets.

@june29
Created June 3, 2013 02:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save june29/5695863 to your computer and use it in GitHub Desktop.
Save june29/5695863 to your computer and use it in GitHub Desktop.
callbackを使って協調的に動作するクラスの例を示すためのコード
class TasuHito
constructor: (base) ->
@base = base
@tashitaAto = null
tasu: (number) =>
result = number + @base
console.log result
setTimeout =>
@tashitaAto(result) if @tashitaAto
, 1000
class KakeruHito
constructor: (base) ->
@base = base
@kaketaAto = null
kakeru: (number) =>
result = number * @base
console.log result
setTimeout =>
@kaketaAto(result) if @kaketaAto
, 1000
tasuHito = new TasuHito(3)
kakeruHito = new KakeruHito(2)
tasuHito.tashitaAto = kakeruHito.kakeru
kakeruHito.kaketaAto = tasuHito.tasu
tasuHito.tasu(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment