Created
July 14, 2011 12:26
-
-
Save bwesterb/1082355 to your computer and use it in GitHub Desktop.
JavaScript Quine
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
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