Skip to content

Instantly share code, notes, and snippets.

@dratini0
Forked from 140bytes/LICENSE.txt
Created April 15, 2012 12:06
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 dratini0/2392358 to your computer and use it in GitHub Desktop.
Save dratini0/2392358 to your computer and use it in GitHub Desktop.
Quine -- 140byt.es entry
(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>
@p01
Copy link

p01 commented Apr 15, 2012

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 between return and (a?.....)

Why not just:

function f(){return''+f}

@p01
Copy link

p01 commented Apr 15, 2012

The document.write version doesn't make much sense either :\ Plus it's exactly the same toString() call.

@dratini0
Copy link
Author

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.

@p01
Copy link

p01 commented Apr 15, 2012

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

@dratini0
Copy link
Author

dratini0 commented Apr 15, 2012 via email

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