-
-
Save dratini0/2392358 to your computer and use it in GitHub Desktop.
Quine -- 140byt.es entry
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
(function f(){ //start named function expression | |
document.write('('+f+')()') //convert itself to a string, and wrap the result in (...)() (for calling) | |
})() //call it |
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
(function f(){document.write('('+f+')()')})() |
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
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. |
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
{ | |
"name": "quine", | |
"description": "A very simple javascript quine", | |
"keywords": [ | |
"quine", | |
"useless", | |
"simple", | |
"named function expression" | |
] | |
} |
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
<!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> |
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
You are right. I will try without it. I did not know about that, it makes
much more sense. Thank you.
…On Apr 15, 2012 9:47 PM, "Mathieu 'p01' Henri" < ***@***.***> wrote:
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
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/2392358
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
document.write
version doesn't make much sense either :\ Plus it's exactly the sametoString()
call.