-
-
Save dratini0/2392358 to your computer and use it in GitHub Desktop.
(function f(){ //start named function expression | |
document.write('('+f+')()') //convert itself to a string, and wrap the result in (...)() (for calling) | |
})() //call it |
(function f(){document.write('('+f+')()')})() |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
Version 2, December 2004 | |
Copyright (C) 2011 Bálint Kovács http://dratini0.co.cc/ | |
Everyone is permitted to copy and distribute verbatim or modified | |
copies of this license document, and changing it is allowed as long | |
as the name is changed. | |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
0. You just DO WHAT THE FUCK YOU WANT TO. |
{ | |
"name": "quine", | |
"description": "A very simple javascript quine", | |
"keywords": [ | |
"quine", | |
"useless", | |
"simple", | |
"named function expression" | |
] | |
} |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Quine</title> | |
</head> | |
<body> | |
<div>Expected value: <b>function f(a){return (a?''+f:f)}</b></div> | |
<div>Actual value: </div> | |
<script> | |
// write a small example that shows off the API for your example | |
// and tests it in one fell swoop. | |
(function f(){document.write('('+f+')()')})() | |
</script> | |
</body> | |
</html> |
The document.write
version doesn't make much sense either :\ Plus it's exactly the same toString()
call.
It now fully matches the definition of a quine: a program which outputs its source. Its source is
(function f(){document.write('('+f+')()')})()
and it outputs the same thing with document.write. (If I did not make any trivial mistake).
But the decision is in yours or jed's or whatever.
Your quines are implicitly using the toString
method, while it is a feature of the language, it spoils the fun of writing quines. Check [1] and [2] for ridiculously small JS quines that don't use the toString
or toSource
methods.
[1] http://web.archive.org/web/20100102034640/http://web-graphics.com/pages/quine.php
[2] http://sla.ckers.org/forum/read.php?24,33201
o_O more like implicit toString() than a real quine. What is the purpose of the argument
a
? At least you can save 1 byte by remove the whitespace betweenreturn
and(a?.....)
Why not just: