Created
November 22, 2013 17:17
-
-
Save secobi/7603548 to your computer and use it in GitHub Desktop.
multiline javascript string demo
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
| //code from http://eli.thegreenplace.net/2013/11/09/javascript-es-5-hack-for-clean-multi-line-strings/ | |
| //typical multiline string variable | |
| var s = "\ | |
| line one\n\ | |
| line two\n\ | |
| line 'three'\n"; | |
| //"hacked" multiline string variable | |
| var MultiString = function(f) { | |
| return f.toString().split('\n').slice(1, -1).join('\n'); | |
| } | |
| var ms = MultiString(function() {/** | |
| line one | |
| line two | |
| line 'three' | |
| **/}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment