diff options
Diffstat (limited to 'files/zh-cn/web/javascript/reference/template_literals/index.html')
-rw-r--r-- | files/zh-cn/web/javascript/reference/template_literals/index.html | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/files/zh-cn/web/javascript/reference/template_literals/index.html b/files/zh-cn/web/javascript/reference/template_literals/index.html index e16b62d850..ed7b7abea1 100644 --- a/files/zh-cn/web/javascript/reference/template_literals/index.html +++ b/files/zh-cn/web/javascript/reference/template_literals/index.html @@ -170,14 +170,14 @@ tag`string text line 1 \n string text line 2`; <p>另外,使用{{jsxref("String.raw()")}} 方法创建原始字符串和使用默认模板函数和字符串连接创建是一样的。</p> -<pre class="brush: js line-numbers language-js"><code class="language-js"><span class="keyword token">var</span> str <span class="operator token">=</span> String<span class="punctuation token">.</span>raw<span class="template-string token"><span class="string token">`Hi\n</span><span class="interpolation token"><span class="interpolation-punctuation punctuation token">${</span><span class="number token">2</span><span class="operator token">+</span><span class="number token">3</span><span class="interpolation-punctuation punctuation token">}</span></span><span class="string token">!`</span></span><span class="punctuation token">;</span> -<span class="comment token">// "Hi\\n5!"</span> +<pre class="brush: js line-numbers language-js"><code class="language-js">var str = String.raw`Hi\n${2+3}!`;var`Hi\n${2+3} +// "Hi\\n5!" -str<span class="punctuation token">.</span>length<span class="punctuation token">;</span> -<span class="comment token">// 6</span> +str.length;. +// 6 -str<span class="punctuation token">.</span><span class="function token">split</span><span class="punctuation token">(</span><span class="string token">''</span><span class="punctuation token">)</span><span class="punctuation token">.</span><span class="function token">join</span><span class="punctuation token">(</span><span class="string token">','</span><span class="punctuation token">)</span><span class="punctuation token">;</span> -<span class="comment token">// "H,i,\\,n,5,!"</span></code> +str.split('').join(',');. +// "H,i,\\,n,5,!"</code> </pre> <h3 id="带标签的模版字面量及转义序列">带标签的模版字面量及转义序列</h3> |