Saturday, June 1, 2024
110
rated 0 times [  115] [ 5]  / answers: 1 / hits: 17845  / 8 Years ago, fri, october 14, 2016, 12:00:00

Let's say we have a multiline es6 Template-String to describe e.g. some URL params for a request:



const fields = `
id,
message,
created_time,
permalink_url,
type
`;


Is there any way to have comments inside that backtick Template-String? Like:



const fields = `
// post id
id,
// post status/message
message,
// .....
created_time,
permalink_url,
type
`;

More From » ecmascript-6

 Answers
100

No.



That syntax is valid, but will just return a string containing n// post idnid, rather than removing the comments and creating a string without them.



If you look at §11.8.6 of the spec, you can see that the only token recognized between the backtick delimiters is TemplateCharacters, which accepts escape sequences, line breaks, and normal characters. In §A.1, SourceCharacter is defined to be any Unicode point (except the ones excluded in 11.8.6).


[#60392] Wednesday, October 12, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
zariahdiamondz

Total Points: 649
Total Questions: 109
Total Answers: 88

Location: Tajikistan
Member since Thu, Apr 14, 2022
2 Years ago
;