Skip to content

Instantly share code, notes, and snippets.

@kentbrew
Last active August 29, 2015 14:03
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 kentbrew/2ae36c935e16f758e76e to your computer and use it in GitHub Desktop.
Save kentbrew/2ae36c935e16f758e76e to your computer and use it in GitHub Desktop.
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