Skip to content

Instantly share code, notes, and snippets.

@jboulhous
Created May 17, 2013 07:43
Show Gist options
  • Save jboulhous/5597551 to your computer and use it in GitHub Desktop.
Save jboulhous/5597551 to your computer and use it in GitHub Desktop.
/**
* What happens here? An anonymous function is created with a function body consisting only of a multi-line comment.
* The comment itself is the very text you want to embed in your application.
* The function is then serialized to a string using toString().
* Interestingly, the call preserves the function signature along with the function body and the comments within.
* Last, a regular expression is run over the serialized form of the function to extract the comment hidden inside.
* The end result assigned to the html variable contains the HTML content within the comment.
*/
var html = (function () {/*
<!DOCTYPE html>
<html>
<body>
<h1>Hello, world!</h1>
</body>
</html>
*/}).toString().match(/[^]*\/\*([^]*)\*\/\}$/)[1];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment