Created
May 17, 2013 07:43
-
-
Save jboulhous/5597551 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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