Currently, more and more are using es6 for most jobs. One caveat is pattern strings.
I like to limit the number of line characters to 80. Therefore, if I need to concatenate a long string, it works fine because concatenation can be multiple lines, such as:
const insert = 'dog'; const str = 'a really long ' + insert + ' can be a great asset for ' + insert + ' when it is a ' + dog;
However, trying to do this using template literals will simply give you a multi-line string with $ {insert}, placing the dog in the resulting string. Not ideal if you want to use template literals for things like collecting URLs, etc.
I have not yet found a good way to maintain a character limit limit and still use long template literals. Does anyone have any ideas?
Another question, marked as accepted, is only a partial answer. Below is another problem with templates that I forgot to include before.
The problem with using the new line characters is that it does not allow you to indent without inserting spaces in the ending line. i.e.
const insert = 'dog'; const str = `a really long ${insert} can be a great asset for\ ${insert} when it is a ${insert}`;
The resulting string is as follows:
a really long dog can be a great asset for dog when it is a dog
This is generally a small issue, but it would be interesting if there was a fix allowing multi-line indentation.
source share