樣板字面值 | javascript string format
在ES2016的規範中,標籤樣板字面值遵守下列跳脫序列(escapesequences)規則:萬國碼(Unicode)跳脫序列由"u"作為開頭,例:u00A9萬國碼位(Unicodecodepoint)由"u{}"作為開頭,例:u{2F804}十六進位制碼由"x"作為開頭,例:xA9十進位制碼由""作為開頭,例:251這表示像是下述的標籤樣板字面值是有問題的,因為根據ECMAScript規範,一個語法分析器會嘗試以萬國碼轉義序列去解析它,然後發現序列有誤:Taggedtemplateliteralsshouldallowtheembeddingoflanguages(forexampleDSLs[1],orLaTeX[2]),whereotherescapessequencesarecommon.TheECMA...
在 ES2016 的規範中,標籤樣板字面值遵守下列跳脫序列(escape sequences)規則:
萬國碼 (Unicode) 跳脫序列由 "u" 作為開頭, 例: u00A9 萬國碼位 (Unicode code point) 由 "u{}" 作為開頭, 例: u{2F804} 十六進位制碼由 "x" 作為開頭, 例: xA9 十進位制碼由 "" 作為開頭, 例: 251這表示像是下述的標籤樣板字面值是有問題的,因為根據 ECMAScript 規範,一個語法分析器會嘗試以萬國碼轉義序列去解析它,然後發現序列有誤:
Tagged template literals should allow the embedding of languages (for example DSLs[1], or LaTeX[2]), where other escapes sequences are common. The ECMAScript proposal Template Literal Revision[3] (stage 4, to be integrated in the ECMAScript 2018 standard) removes the syntax restriction of ECMAScript escape sequences from tagged template literals.
However, illegal escape sequence must still be represented in the "cooked" representation. They will show up as undefined (en-US)[4] element in the "cooked" array:
l be represented in the "cooked" representation. They will show up as undefined (en-US)[5] element in the "cooked" array:
function latex(str) { return { cooked: str[0], raw...