Timeline for How can I assign a multiline string literal to a variable?
Current License: CC BY-SA 4.0
16 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Nov 30, 2024 at 19:48 | history | edited | Peter Mortensen | CC BY-SA 4.0 |
Expanded. Removed meta information (this belongs in comments).
|
| Mar 30, 2020 at 5:38 | history | edited | mplungjan | CC BY-SA 4.0 |
added 230 characters in body
|
| Feb 3, 2016 at 0:00 | comment | added | Ben McIntyre | I've never been brave enough to use this technique in production code, but where I DO use it a lot is in unit testing, where often it's easiest to dump the value of some structure as a (quite long) string and compare it to what it 'should' be. | |
| Jan 17, 2016 at 15:44 | history | edited | mplungjan | CC BY-SA 3.0 |
added 10 characters in body
|
| Aug 17, 2015 at 3:30 | comment | added | mplungjan | I will look when I get to an iMac end of this week | |
| Aug 17, 2015 at 0:19 | comment | added | Steve Bennett |
Still shows undefined throughout the text for me - Chrome/OSX.
|
|
| Jul 27, 2015 at 21:10 | comment | added | Thomas Dignan | Forget the haters. This is the only correct answer bar ES6. All the other answers require concatenation, computation of some sort, or escaping. This is actually pretty cool and I'm going to use it as a way to add documentation to a game I'm working on as a hobby. As long as this trick isn't used for anything that could invoke a bug (I can see how someone would go "Semicolon, derp. Lets put the comment on the next line." and then it breaks your code.) But, is that really a big deal in my hobby game? No, and I can use the cool trick for something useful. Great answer. | |
| Jul 18, 2015 at 5:44 | history | edited | mplungjan | CC BY-SA 3.0 |
added 61 characters in body
|
| Jun 1, 2015 at 16:44 | comment | added | Orwellophile | jsfiddle-fixed - I must have had "you" defined globally in my console. Works now (chrome/osx). The nice thing about adding the comment to a var is that you're not in a function context, jsfiddle-function-heredoc although the function thing would be cool for class methods. might be better to pass it a replace { this: that } object anyways. fun to push something crazy to the limit anyway :) | |
| May 28, 2015 at 17:34 | history | edited | mplungjan | CC BY-SA 3.0 |
deleted 20 characters in body
|
| May 27, 2015 at 16:46 | comment | added | mplungjan | Undefined "you" in chrome for osx | |
| May 27, 2015 at 11:44 | comment | added | Orwellophile |
jsfiddle Implemented with interpolation of local variables, unlimited unique HEREDOCs, method adaptable for function(){/*! style HEREDOC aswell. Abbreviated usage: HEREDOC="EOF";/*!EOF ... EOF*/ currentScript().split(HEREDOC)[2];
|
|
| May 27, 2015 at 10:51 | comment | added | Orwellophile | But it was a unique answer. I'm actually writing a polyfill now, but mainly because jsfiddle loads your script inline. I want to code the *interpolation –– (abandoning #{} because ES7 decrees ${this.var}. | |
| May 27, 2015 at 10:10 | comment | added | mplungjan | currentScript ? In what browsers? My answer is more than 2 years old :) | |
| May 27, 2015 at 10:00 | comment | added | Orwellophile | That's horrific. +1. And you can use document.currentScript instead of getElement... | |
| Feb 17, 2013 at 9:56 | history | answered | mplungjan | CC BY-SA 3.0 |