Skip to content

Instantly share code, notes, and snippets.

@bwesterb
Created July 14, 2011 12:26
Show Gist options
  • Save bwesterb/1082355 to your computer and use it in GitHub Desktop.
Save bwesterb/1082355 to your computer and use it in GitHub Desktop.
JavaScript Quine
phi = function(c) {
return eval("("+c+")").apply(null,
Array.prototype.slice.call(arguments, 1));
};
s11 = function(c, x) {
return "function(){"+
"return ("+c+").apply(null,["+
JSON.stringify(x)+"].concat("+
"Array.prototype.slice.call(arguments,0)));"+
"}";
}
i_am = function(p, x) {
return ("I am\n\n"+p+"\n\nexecuted on"+x);
}
quine = function(c) {
return "function(x){"+
"var f = (function(e,x) {"+
"return ("+c+")(s11(e,e), x);"+
"});"+
"return phi(s11(f.toString(), f.toString()), x);"+
"}";
}
console.debug(phi(quine(i_am.toString()), " argument"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment