Skip to content

Instantly share code, notes, and snippets.

@qntm
Last active October 16, 2023 12:39
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qntm/56996c1bd0c342114ea5 to your computer and use it in GitHub Desktop.
Save qntm/56996c1bd0c342114ea5 to your computer and use it in GitHub Desktop.
// TODO: longer method name
Function.prototype.extractBlockCommentAsMultilineString = function() {
return this.toString().match(/^function \(\)\{\s*\/\*((?:[^*]|\*+[^*\/])*)\*+\/\s*\}$/)[1];
};
var s = function(){/*
STRING
GOES
HERE
*/}.extractBlockCommentAsMultilineString();
console.log("\r\n\tSTRING\r\n\tGOES\r\n\tHERE\r\n" === s); // true, possibly
@riking
Copy link

riking commented Aug 17, 2015

extractMultilineStringFromFunctionContainingOnlyABlockComment()

@qntm
Copy link
Author

qntm commented Oct 16, 2023

This was funnier before template literals.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment