Is it possible to have a comment inside a es6 Template-String?

后端 未结 4 1136
攒了一身酷
攒了一身酷 2021-01-01 13:17

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,
           


        
4条回答
  •  别那么骄傲
    2021-01-01 13:37

    No.

    That syntax is valid, but will just return a string containing \n// post id\nid, 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).

提交回复
热议问题