Created
June 3, 2013 02:46
-
-
Save june29/5695863 to your computer and use it in GitHub Desktop.
callbackを使って協調的に動作するクラスの例を示すためのコード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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