Skip to content

Instantly share code, notes, and snippets.

@en30
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save en30/9d0780cab8c3534981e3 to your computer and use it in GitHub Desktop.
Save en30/9d0780cab8c3534981e3 to your computer and use it in GitHub Desktop.
// 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);
};
})();
@en30
Copy link
Author

en30 commented Nov 2, 2014

言語仕様を利用してシンプルにしていたからこそ「面白かった」ということなんですな

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment