Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Multi-Line Strings in JavaScript

Multi-line strings in JavaScript

Playing around with concepts shown by Sindre Sorhus in https://github.com/sindresorhus/multiline, which had some optimizations that confused me about the idea's basis.

Paste me into your JavaScript console:

var getMultiLineString = function(func) { 
  var ret, str, temp;
  ret = '';
  if (typeof func === 'function') {
    str = func.toString();
    if (str) {
      temp = str.split('/*');
      if (temp[1]) {
        ret = temp[1].split('*/')[0];
      }
    }
  }
  return ret;
}

var testme = (function(){/*

// some html to render

<ul>
   <li>woo</li>
   <li>yay</li>
</ul>

*/});

console.log(getMultiLineString(testme));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment