Advertisement
aaaaaa123456789

JavaScript quine

Apr 15th, 2014
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var quote = '"';
  2. var apostrophe = "'";
  3. var print_out, main;
  4.  
  5. var ce_code = "function concat_eval (lines) {var l; var c = ''; for (l = 0; l < lines.length; l ++) c = c.concat(lines[l]); return eval(c);}";
  6. eval(ce_code);
  7.  
  8. var po_code = [
  9.   "print_out = function (variable_name, contents) {",
  10.   "  if ((typeof contents) == 'string') {",
  11.   "    document.writeln('var ', variable_name, ' = ', quote, contents, quote, ';');",
  12.   "    document.writeln('eval(', variable_name, ');');",
  13.   "  } else {",
  14.   "    document.writeln('var ', variable_name, ' = [');",
  15.   "    var current_line;",
  16.   "    for (current_line = 0; current_line < contents.length; current_line ++)",
  17.   "      document.writeln('  ', quote, contents[current_line], quote, (current_line == (contents.length - 1)) ? '' : ',');",
  18.   "    document.writeln('];');",
  19.   "    document.writeln('concat_eval(', variable_name, ');');",
  20.   "  }",
  21.   "  document.writeln();",
  22.   "}"
  23. ];
  24. concat_eval(po_code);
  25.  
  26. var main_code = [
  27.   "main = function () {",
  28.   "  var code_items = ['ce_code', 'po_code', 'main_code'];",
  29.   "  document.writeln('var quote = ', apostrophe, quote, apostrophe, ';');",
  30.   "  document.writeln('var apostrophe = ', quote, apostrophe, quote, ';');",
  31.   "  document.writeln('var print_out, main;');",
  32.   "  document.writeln();",
  33.   "  var code_item;",
  34.   "  for (code_item = 0; code_item < code_items.length; code_item ++)",
  35.   "    print_out(code_items[code_item], eval(code_items[code_item]));",
  36.   "  document.writeln('main();');",
  37.   "}"
  38. ];
  39. concat_eval(main_code);
  40.  
  41. main();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement