Last active
August 29, 2015 14:08
-
-
Save en30/9d0780cab8c3534981e3 to your computer and use it in GitHub Desktop.
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
// https://gist.github.com/kazuho/3300555 | |
// の参照先の切り替えを隠蔽しようと思ったら | |
// ただの愚直な実装になった | |
var generator = function(n, name){ | |
var current = {f: function(){ return name; }}, | |
doNothing = function(){}, | |
o = current; | |
while(--n) { | |
o.next = {f: doNothing}; | |
o = o.next; | |
} | |
o.next = current; | |
return function(){ | |
current = current.next; | |
return current.f(); | |
}; | |
}; | |
var fizzbuzz = (function(){ | |
var n = 0, | |
fizz = generator(3, "Fizz"), | |
buzz = generator(5, "Buzz"); | |
return function () { | |
++n; | |
console.log((fizz() || "") + (buzz() || "") || n); | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
言語仕様を利用してシンプルにしていたからこそ「面白かった」ということなんですな