Javascript HEREDOC

Implementing HEREDOC as a in-function-def comment. http://stackoverflow.com/questions/805107/creating-multiline-strings-in-javascript

by orwellophile

HTML

<link rel="stylesheet" href="https://nt4.com/css/fonts/clean.css">
<script src="https://nt4.com/js/useragent.js"></script>
<h3>javascript HEREDOC</h3>
<h4>in-function-def comment method</h4>
<div class="output"></div>

CSS

body {
    font-family: "clean", "Helvetica Neue", sans-serif;
    margin: 1em;
}

h4 {
    font-size: 1.2em;
}
h3 { 
    font-size: 1.5em;
}

.output {
  white-space: pre-wrap;
  border: 1px solid thistle;
  border-radius: 15px;
  min-height: 200px;
  min-width: 200px;
  display: inline-block;
  margin-top: 1em;
  padding: 0.7em;
}

JavaScript

!function() {
    var ref;
    you = "you"; // ${you} will be replaced with this, note global scope

    makeOutput((ref = function EOF(){ /*!<<<EOF 
   "What the hell choice is there? ${you} cry, ${you} continue to cry, because ${you} don't ever completely come back from where ${you} went with him — a fragment broken off ${you}r pulsing, pumping heart is there still. A nick out of it. 

   A cut that never heals. And if, when it happens to ${you} over and over again in life, too much of ${you}r heart does finally go away, then ${you} can't feel grief any more. And then ${you} ${you}rself are ready to die. 

   ${you}'ll walk up the inclined ladder and someone else will remain behind grieving for ${you}." 

   -- Philip K. Dick, "Flow my Tears, the Policemen Said"
EOF
*/ }).toString().split(ref.name)[2]

  // Optional ES6 style variable interpolation:
  .replace(/\$\{([^}]+)\}/g, 
       function(outer, inner, pos) {
           return this[inner];
   })
               
) 
}();

function makeOutput(output) {
  $('.output').text(output);
  $('.output').css('width', $(window).width() - 64 + "px")
};